From bc8b4c32107dbe0eb007260a6e749692405e9750 Mon Sep 17 00:00:00 2001 From: Casper Hornstrup Date: Tue, 12 Jun 2001 17:35:46 +0000 Subject: [PATCH] Removed old wine code svn path=/trunk/; revision=1963 --- reactos/lib/user32/controls/button.c | 598 ---- reactos/lib/user32/controls/combo.c | 1570 ---------- reactos/lib/user32/controls/edit.c | 3803 ----------------------- reactos/lib/user32/controls/icontitle.c | 250 -- reactos/lib/user32/controls/listbox.c | 2559 --------------- reactos/lib/user32/controls/menu.c | 1345 -------- reactos/lib/user32/controls/scroll.c | 1446 --------- reactos/lib/user32/controls/static.c | 509 --- reactos/lib/user32/controls/widgets.c | 118 - reactos/lib/user32/graphics/caret.c | 297 -- reactos/lib/user32/graphics/draw.c | 14 - reactos/lib/user32/graphics/fill.c | 84 - reactos/lib/user32/graphics/icon.c | 208 -- reactos/lib/user32/graphics/rect.c | 256 -- reactos/lib/user32/graphics/syscol.c | 160 - reactos/lib/user32/graphics/text.c | 73 - reactos/lib/user32/internal/dce.c | 440 --- reactos/lib/user32/internal/defwnd.c | 435 --- reactos/lib/user32/internal/dialog.c | 1005 ------ reactos/lib/user32/internal/event.c | 45 - reactos/lib/user32/internal/heapdup.c | 119 - reactos/lib/user32/internal/menu.c | 2532 --------------- reactos/lib/user32/internal/msg.c | 1178 ------- reactos/lib/user32/internal/nc.c | 2320 -------------- reactos/lib/user32/internal/paint.c | 283 -- reactos/lib/user32/internal/queue.c | 707 ----- reactos/lib/user32/internal/region.c | 4 - reactos/lib/user32/internal/scroll.c | 1097 ------- reactos/lib/user32/internal/signal.c | 6 - reactos/lib/user32/internal/text.c | 720 ----- reactos/lib/user32/internal/timer.c | 293 -- reactos/lib/user32/internal/uitools.c | 1326 -------- reactos/lib/user32/internal/win.c | 1103 ------- reactos/lib/user32/internal/winpos.c | 1158 ------- reactos/lib/user32/makefile_rex | 16 +- reactos/lib/user32/misc/bitmap.c | 95 - reactos/lib/user32/misc/cursor.c | 34 - reactos/lib/user32/misc/dllmain.c | 47 +- reactos/lib/user32/misc/exitwin.c | 108 - reactos/lib/user32/misc/main.c | 43 - reactos/lib/user32/misc/string.c | 814 ----- reactos/lib/user32/misc/stubs.c | 1393 +-------- reactos/lib/user32/misc/stubsa.c | 309 -- reactos/lib/user32/misc/stubsw.c | 321 -- reactos/lib/user32/misc/sysmetr.c | 279 -- reactos/lib/user32/misc/vk.c | 77 - reactos/lib/user32/misc/winstat.c | 240 -- reactos/lib/user32/resources/sysres.c | 72 - 48 files changed, 58 insertions(+), 31851 deletions(-) delete mode 100644 reactos/lib/user32/controls/button.c delete mode 100644 reactos/lib/user32/controls/combo.c delete mode 100644 reactos/lib/user32/controls/edit.c delete mode 100644 reactos/lib/user32/controls/icontitle.c delete mode 100644 reactos/lib/user32/controls/listbox.c delete mode 100644 reactos/lib/user32/controls/menu.c delete mode 100644 reactos/lib/user32/controls/scroll.c delete mode 100644 reactos/lib/user32/controls/static.c delete mode 100644 reactos/lib/user32/controls/widgets.c delete mode 100644 reactos/lib/user32/graphics/caret.c delete mode 100644 reactos/lib/user32/graphics/draw.c delete mode 100644 reactos/lib/user32/graphics/fill.c delete mode 100644 reactos/lib/user32/graphics/icon.c delete mode 100644 reactos/lib/user32/graphics/rect.c delete mode 100644 reactos/lib/user32/graphics/syscol.c delete mode 100644 reactos/lib/user32/graphics/text.c delete mode 100644 reactos/lib/user32/internal/dce.c delete mode 100644 reactos/lib/user32/internal/defwnd.c delete mode 100644 reactos/lib/user32/internal/dialog.c delete mode 100644 reactos/lib/user32/internal/event.c delete mode 100644 reactos/lib/user32/internal/heapdup.c delete mode 100644 reactos/lib/user32/internal/menu.c delete mode 100644 reactos/lib/user32/internal/msg.c delete mode 100644 reactos/lib/user32/internal/nc.c delete mode 100644 reactos/lib/user32/internal/paint.c delete mode 100644 reactos/lib/user32/internal/queue.c delete mode 100644 reactos/lib/user32/internal/region.c delete mode 100644 reactos/lib/user32/internal/scroll.c delete mode 100644 reactos/lib/user32/internal/signal.c delete mode 100644 reactos/lib/user32/internal/text.c delete mode 100644 reactos/lib/user32/internal/timer.c delete mode 100644 reactos/lib/user32/internal/uitools.c delete mode 100644 reactos/lib/user32/internal/win.c delete mode 100644 reactos/lib/user32/internal/winpos.c delete mode 100644 reactos/lib/user32/misc/bitmap.c delete mode 100644 reactos/lib/user32/misc/cursor.c delete mode 100644 reactos/lib/user32/misc/exitwin.c delete mode 100644 reactos/lib/user32/misc/main.c delete mode 100644 reactos/lib/user32/misc/string.c delete mode 100644 reactos/lib/user32/misc/stubsa.c delete mode 100644 reactos/lib/user32/misc/stubsw.c delete mode 100644 reactos/lib/user32/misc/sysmetr.c delete mode 100644 reactos/lib/user32/misc/vk.c delete mode 100644 reactos/lib/user32/misc/winstat.c delete mode 100644 reactos/lib/user32/resources/sysres.c diff --git a/reactos/lib/user32/controls/button.c b/reactos/lib/user32/controls/button.c deleted file mode 100644 index fe8ed5b2880..00000000000 --- a/reactos/lib/user32/controls/button.c +++ /dev/null @@ -1,598 +0,0 @@ -/* File: button.c -- Button type widgets - * - * Copyright (C) 1993 Johannes Ruscheinski - * Copyright (C) 1993 David Metcalfe - * Copyright (C) 1994 Alexandre Julliard - */ -#include -#include -#include -#include -#include -#include -#include - - -static void PB_Paint( WND *wndPtr, HDC hDC, WORD action ); -static void PB_PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text); -static void CB_Paint( WND *wndPtr, HDC hDC, WORD action ); -static void GB_Paint( WND *wndPtr, HDC hDC, WORD action ); -static void UB_Paint( WND *wndPtr, HDC hDC, WORD action ); -static void OB_Paint( WND *wndPtr, HDC hDC, WORD action ); -static void BUTTON_CheckAutoRadioButton( WND *wndPtr ); - -#define MAX_BTN_TYPE 12 - -static const WORD maxCheckState[MAX_BTN_TYPE] = -{ - BUTTON_UNCHECKED, /* BS_PUSHBUTTON */ - BUTTON_UNCHECKED, /* BS_DEFPUSHBUTTON */ - BUTTON_CHECKED, /* BS_CHECKBOX */ - BUTTON_CHECKED, /* BS_AUTOCHECKBOX */ - BUTTON_CHECKED, /* BS_RADIOBUTTON */ - BUTTON_3STATE, /* BS_3STATE */ - BUTTON_3STATE, /* BS_AUTO3STATE */ - BUTTON_UNCHECKED, /* BS_GROUPBOX */ - BUTTON_UNCHECKED, /* BS_USERBUTTON */ - BUTTON_CHECKED, /* BS_AUTORADIOBUTTON */ - BUTTON_UNCHECKED, /* Not defined */ - BUTTON_UNCHECKED /* BS_OWNERDRAW */ -}; - -typedef void (*pfPaint)( WND *wndPtr, HDC hdc, WORD action ); - -static const pfPaint btnPaintFunc[MAX_BTN_TYPE] = -{ - PB_Paint, /* BS_PUSHBUTTON */ - PB_Paint, /* BS_DEFPUSHBUTTON */ - CB_Paint, /* BS_CHECKBOX */ - CB_Paint, /* BS_AUTOCHECKBOX */ - CB_Paint, /* BS_RADIOBUTTON */ - CB_Paint, /* BS_3STATE */ - CB_Paint, /* BS_AUTO3STATE */ - GB_Paint, /* BS_GROUPBOX */ - UB_Paint, /* BS_USERBUTTON */ - CB_Paint, /* BS_AUTORADIOBUTTON */ - NULL, /* Not defined */ - OB_Paint /* BS_OWNERDRAW */ -}; - -#define PAINT_BUTTON(wndPtr,style,action) \ - if (btnPaintFunc[style]) { \ - HDC hdc = GetDC( (wndPtr)->hwndSelf ); \ - (btnPaintFunc[style])(wndPtr,hdc,action); \ - ReleaseDC( (wndPtr)->hwndSelf, hdc ); } - -#define BUTTON_SEND_CTLCOLOR(wndPtr,hdc) \ - SendMessageA( GetParent((wndPtr)->hwndSelf), WM_CTLCOLORBTN, \ - (WPARAM)(hdc), (LPARAM)(wndPtr)->hwndSelf ) - -static HBITMAP hbitmapCheckBoxes = 0; -static WORD checkBoxWidth = 0, checkBoxHeight = 0; - - -/*********************************************************************** - * ButtonWndProc - */ -LRESULT WINAPI ButtonWndProc( HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam ) -{ - RECT rect; - POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - WND *wndPtr = WIN_FindWndPtr(hWnd); - BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra; - LONG style = wndPtr->dwStyle & 0x0f; - - switch (uMsg) - { - case WM_GETDLGCODE: - switch(style) - { - case BS_PUSHBUTTON: return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON; - case BS_DEFPUSHBUTTON: return DLGC_BUTTON | DLGC_DEFPUSHBUTTON; - case BS_RADIOBUTTON: - case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON; - default: return DLGC_BUTTON; - } - - case WM_ENABLE: - PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE ); - break; - - case WM_CREATE: - if (!hbitmapCheckBoxes) - { - BITMAP bmp; - hbitmapCheckBoxes = LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CHECKBOXES)); - GetObjectA( hbitmapCheckBoxes, sizeof(bmp), &bmp ); - checkBoxWidth = bmp.bmWidth / 4; - checkBoxHeight = bmp.bmHeight / 3; - } - if (style < 0L || style >= MAX_BTN_TYPE) return -1; /* abort */ - infoPtr->state = BUTTON_UNCHECKED; - infoPtr->hFont = 0; - return 0; - - case WM_ERASEBKGND: - return 1; - - case WM_PAINT: - if (btnPaintFunc[style]) - { - PAINTSTRUCT ps; - HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps ); - SetBkMode( hdc, OPAQUE ); - (btnPaintFunc[style])( wndPtr, hdc, ODA_DRAWENTIRE ); - if( !wParam ) EndPaint( hWnd, &ps ); - } - break; - - case WM_LBUTTONDOWN: - case WM_LBUTTONDBLCLK: - SendMessageA( hWnd, BM_SETSTATE, TRUE, 0 ); - SetFocus( hWnd ); - SetCapture( hWnd ); - break; - - case WM_LBUTTONUP: - ReleaseCapture(); - if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break; - SendMessageA( hWnd, BM_SETSTATE, FALSE, 0 ); - GetClientRect( hWnd, &rect ); - if (PtInRect( &rect, pt )) - { - switch(style) - { - case BS_AUTOCHECKBOX: - SendMessageA( hWnd, BM_SETCHECK, - !(infoPtr->state & BUTTON_CHECKED), 0 ); - break; - case BS_AUTORADIOBUTTON: - SendMessageA( hWnd, BM_SETCHECK, TRUE, 0 ); - break; - case BS_AUTO3STATE: - SendMessageA( hWnd, BM_SETCHECK, - (infoPtr->state & BUTTON_3STATE) ? 0 : - ((infoPtr->state & 3) + 1), 0 ); - break; - } - SendMessageA( GetParent(hWnd), WM_COMMAND, - MAKEWPARAM( wndPtr->wIDmenu, BN_CLICKED ), (LPARAM)hWnd); - } - break; - - case WM_MOUSEMOVE: - if (GetCapture() == hWnd) - { - GetClientRect( hWnd, &rect ); - SendMessageA( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 ); - } - break; - - case WM_NCHITTEST: - if(style == BS_GROUPBOX) return HTTRANSPARENT; - return DefWindowProcA( hWnd, uMsg, wParam, lParam ); - - case WM_SETTEXT: - DEFWND_SetTextA( wndPtr, (LPCSTR)lParam ); - if( wndPtr->dwStyle & WS_VISIBLE ) - PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE ); - return 0; - - case WM_SETFONT: - infoPtr->hFont = (HFONT)wParam; - if (lParam && (wndPtr->dwStyle & WS_VISIBLE)) - PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE ); - break; - - case WM_GETFONT: - return (LRESULT)infoPtr->hFont; - - case WM_SETFOCUS: - infoPtr->state |= BUTTON_HASFOCUS; - if (style == BS_AUTORADIOBUTTON) - { - SendMessageA( hWnd, BM_SETCHECK, 1, 0 ); - } - PAINT_BUTTON( wndPtr, style, ODA_FOCUS ); - break; - - case WM_KILLFOCUS: - infoPtr->state &= ~BUTTON_HASFOCUS; - PAINT_BUTTON( wndPtr, style, ODA_FOCUS ); - InvalidateRect( hWnd, NULL, TRUE ); - break; - - case WM_SYSCOLORCHANGE: - InvalidateRect( hWnd, NULL, FALSE ); - break; - - case BM_SETSTYLE: - if ((wParam & 0x0f) >= MAX_BTN_TYPE) break; - wndPtr->dwStyle = (wndPtr->dwStyle & 0xfffffff0) - | (wParam & 0x0000000f); - style = wndPtr->dwStyle & 0x0000000f; - PAINT_BUTTON( wndPtr, style, ODA_DRAWENTIRE ); - break; - - case BM_GETCHECK: - return infoPtr->state & 3; - - case BM_SETCHECK: - if (wParam > maxCheckState[style]) wParam = maxCheckState[style]; - if ((infoPtr->state & 3) != wParam) - { - if ((style == BS_RADIOBUTTON) || (style == BS_AUTORADIOBUTTON)) - { - if (wParam) - wndPtr->dwStyle |= WS_TABSTOP; - else - wndPtr->dwStyle &= ~WS_TABSTOP; - } - infoPtr->state = (infoPtr->state & ~3) | wParam; - PAINT_BUTTON( wndPtr, style, ODA_SELECT ); - } - if ((style == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED)) - BUTTON_CheckAutoRadioButton( wndPtr ); - break; - - case BM_GETSTATE: - return infoPtr->state; - - case BM_SETSTATE: - if (wParam) - { - if (infoPtr->state & BUTTON_HIGHLIGHTED) break; - infoPtr->state |= BUTTON_HIGHLIGHTED; - } - else - { - if (!(infoPtr->state & BUTTON_HIGHLIGHTED)) break; - infoPtr->state &= ~BUTTON_HIGHLIGHTED; - } - PAINT_BUTTON( wndPtr, style, ODA_SELECT ); - break; - - default: - return DefWindowProcA(hWnd, uMsg, wParam, lParam); - } - return 0; -} - - -/********************************************************************** - * Push Button Functions - */ - -static void PB_Paint( WND *wndPtr, HDC hDC, WORD action ) -{ - RECT rc; - HPEN hOldPen; - HBRUSH hOldBrush; - BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra; - - GetClientRect( wndPtr->hwndSelf, &rc ); - - /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */ - if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont ); - BUTTON_SEND_CTLCOLOR( wndPtr, hDC ); - hOldPen = (HPEN)SelectObject(hDC, GetSysColorPen(COLOR_WINDOWFRAME)); - hOldBrush =(HBRUSH)SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE)); - SetBkMode(hDC, TRANSPARENT); - Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); - if (action == ODA_DRAWENTIRE) - { - SetPixel( hDC, rc.left, rc.top, GetSysColor(COLOR_WINDOW) ); - SetPixel( hDC, rc.left, rc.bottom-1, GetSysColor(COLOR_WINDOW) ); - SetPixel( hDC, rc.right-1, rc.top, GetSysColor(COLOR_WINDOW) ); - SetPixel( hDC, rc.right-1, rc.bottom-1, GetSysColor(COLOR_WINDOW)); - } - InflateRect( &rc, -1, -1 ); - - if ((wndPtr->dwStyle & 0x000f) == BS_DEFPUSHBUTTON) - { - Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); - InflateRect( &rc, -1, -1 ); - } - - if (infoPtr->state & BUTTON_HIGHLIGHTED) - { - /* draw button shadow: */ - SelectObject(hDC, GetSysColorBrush(COLOR_BTNSHADOW)); - PatBlt(hDC, rc.left, rc.top, 1, rc.bottom-rc.top, PATCOPY ); - PatBlt(hDC, rc.left, rc.top, rc.right-rc.left, 1, PATCOPY ); - rc.left += 2; /* To position the text down and right */ - rc.top += 2; - } else { - rc.right++, rc.bottom++; - DrawEdge( hDC, &rc, EDGE_RAISED, BF_RECT ); - rc.right--, rc.bottom--; - } - - /* draw button label, if any: */ -// && wndPtr->text[0] - if (wndPtr->text ) - { - LOGBRUSH lb; - GetObject( GetSysColorBrush(COLOR_BTNFACE), sizeof(lb), &lb ); - if (wndPtr->dwStyle & WS_DISABLED && - GetSysColor(COLOR_GRAYTEXT)==lb.lbColor) - /* don't write gray text on gray bkg */ - PB_PaintGrayOnGray(hDC,infoPtr->hFont,&rc,wndPtr->text); - else - { - SetTextColor( hDC, (wndPtr->dwStyle & WS_DISABLED) ? - GetSysColor(COLOR_GRAYTEXT) : - GetSysColor(COLOR_BTNTEXT) ); - DrawTextA( hDC, wndPtr->text, -1, &rc, - DT_SINGLELINE | DT_CENTER | DT_VCENTER ); - /* do we have the focus? */ - if (infoPtr->state & BUTTON_HASFOCUS) - { - RECT r = { 0, 0, 0, 0 }; - INT xdelta, ydelta; - - DrawTextA( hDC, wndPtr->text, -1, &r, - DT_SINGLELINE | DT_CALCRECT ); - xdelta = ((rc.right - rc.left) - (r.right - r.left) - 1) / 2; - ydelta = ((rc.bottom - rc.top) - (r.bottom - r.top) - 1) / 2; - if (xdelta < 0) xdelta = 0; - if (ydelta < 0) ydelta = 0; - InflateRect( &rc, -xdelta, -ydelta ); - DrawFocusRect( hDC, &rc ); - } - } - } - - SelectObject( hDC, hOldPen ); - SelectObject( hDC, hOldBrush ); -} - - -/********************************************************************** - * Push Button sub function [internal] - * using a raster brush to avoid gray text on gray background - */ - -void PB_PaintGrayOnGray(HDC hDC,HFONT hFont,RECT *rc,char *text) -{ - static const int Pattern[] = {0xAA,0x55,0xAA,0x55,0xAA,0x55,0xAA,0x55}; - HBITMAP hbm = CreateBitmap( 8, 8, 1, 1, Pattern ); - HDC hdcMem = CreateCompatibleDC(hDC); - HBITMAP hbmMem; - HBRUSH hBr; - RECT rect,rc2; - - rect=*rc; - DrawTextA( hDC, text, -1, &rect, DT_SINGLELINE | DT_CALCRECT); - rc2=rect; - rect.left=(rc->right-rect.right)/2; /* for centering text bitmap */ - rect.top=(rc->bottom-rect.bottom)/2; - hbmMem = CreateCompatibleBitmap( hDC,rect.right,rect.bottom ); - SelectObject( hdcMem, hbmMem); - hBr = SelectObject( hdcMem, CreatePatternBrush(hbm) ); - DeleteObject( hbm ); - PatBlt( hdcMem,0,0,rect.right,rect.bottom,WHITENESS); - if (hFont) SelectObject( hdcMem, hFont); - DrawTextA( hdcMem, text, -1, &rc2, DT_SINGLELINE); - PatBlt( hdcMem,0,0,rect.right,rect.bottom,0xFA0089); - DeleteObject( SelectObject( hdcMem,hBr) ); - BitBlt(hDC,rect.left,rect.top,rect.right,rect.bottom,hdcMem,0,0,0x990000); - DeleteDC( hdcMem); - DeleteObject( hbmMem ); -} - - -/********************************************************************** - * Check Box & Radio Button Functions - */ - -static void CB_Paint( WND *wndPtr, HDC hDC, WORD action ) -{ - RECT rbox, rtext, client; - HBRUSH hBrush; - int textlen, delta; - BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra; - - textlen = 0; - GetClientRect(wndPtr->hwndSelf, &client); - rbox = rtext = client; - - if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont ); - - /* Something is still not right, checkboxes (and edit controls) - * in wsping have white backgrounds instead of dark grey. - * BUTTON_SEND_CTLCOLOR() is even worse since it returns 0 in this - * particular case and the background is not painted at all. - */ - - hBrush = GetControlBrush( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN ); - - if (wndPtr->dwStyle & BS_LEFTTEXT) - { - /* magic +4 is what CTL3D expects */ - - rtext.right -= checkBoxWidth + 4; - rbox.left = rbox.right - checkBoxWidth; - } - else - { - rtext.left += checkBoxWidth + 4; - rbox.right = checkBoxWidth; - } - - /* Draw the check-box bitmap */ - - - if (wndPtr->text) { - textlen = lstrlenA( wndPtr->text ); - } - if (action == ODA_DRAWENTIRE || action == ODA_SELECT) - { - HDC hMemDC = CreateCompatibleDC( hDC ); - int x = 0, y = 0; - delta = (rbox.bottom - rbox.top - checkBoxHeight) >> 1; - - if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush ); - else FillRect( hDC, &client, hBrush ); - - if (infoPtr->state & BUTTON_HIGHLIGHTED) x += 2 * checkBoxWidth; - if (infoPtr->state & (BUTTON_CHECKED | BUTTON_3STATE)) x += checkBoxWidth; - if (((wndPtr->dwStyle & 0x0f) == BS_RADIOBUTTON) || - ((wndPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) y += checkBoxHeight; - else if (infoPtr->state & BUTTON_3STATE) y += 2 * checkBoxHeight; - - SelectObject( hMemDC, hbitmapCheckBoxes ); - BitBlt( hDC, rbox.left, rbox.top + delta, checkBoxWidth, - checkBoxHeight, hMemDC, x, y, SRCCOPY ); - DeleteDC( hMemDC ); - - if( textlen && action != ODA_SELECT ) - { - if (wndPtr->dwStyle & WS_DISABLED) - SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) ); - DrawTextA( hDC, wndPtr->text, textlen, &rtext, - DT_SINGLELINE | DT_VCENTER ); - textlen = 0; /* skip DrawText() below */ - } - } - - if ((action == ODA_FOCUS) || - ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS))) - { - /* again, this is what CTL3D expects */ - - SetRectEmpty(&rbox); - if( textlen ) - DrawTextA( hDC, wndPtr->text, textlen, &rbox, - DT_SINGLELINE | DT_CALCRECT ); - textlen = rbox.bottom - rbox.top; - delta = ((rtext.bottom - rtext.top) - textlen)/2; - rbox.bottom = (rbox.top = rtext.top + delta - 1) + textlen + 2; - textlen = rbox.right - rbox.left; - rbox.right = (rbox.left += --rtext.left) + textlen + 2; - IntersectRect(&rbox, &rbox, &rtext); - DrawFocusRect( hDC, &rbox ); - } -} - - -/********************************************************************** - * BUTTON_CheckAutoRadioButton - * - * wndPtr is checked, uncheck every other auto radio button in group - */ -static void BUTTON_CheckAutoRadioButton( WND *wndPtr ) -{ - HWND parent, sibling, start; - WND *sibPtr; - if (!(wndPtr->dwStyle & WS_CHILD)) return; - parent = wndPtr->parent->hwndSelf; - /* assure that starting control is not disabled or invisible */ - start = sibling = GetNextDlgGroupItem( parent, wndPtr->hwndSelf, TRUE ); - do - { - - if (!sibling) break; - sibPtr = WIN_FindWndPtr(sibling); - if (!sibPtr) break; - if ((wndPtr->hwndSelf != sibling) && - ((sibPtr->dwStyle & 0x0f) == BS_AUTORADIOBUTTON)) - SendMessageA( sibling, BM_SETCHECK, BUTTON_UNCHECKED, 0 ); - sibling = GetNextDlgGroupItem( parent, sibling, FALSE ); - } while (sibling != start); -} - - -/********************************************************************** - * Group Box Functions - */ - -static void GB_Paint( WND *wndPtr, HDC hDC, WORD action ) -{ - RECT rc, rcFrame; - BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra; - - if (action != ODA_DRAWENTIRE) return; - - BUTTON_SEND_CTLCOLOR( wndPtr, hDC ); - - GetClientRect( wndPtr->hwndSelf, &rc); - if (TWEAK_WineLook == WIN31_LOOK) { - HPEN hPrevPen = SelectObject( hDC, - GetSysColorPen(COLOR_WINDOWFRAME)); - HBRUSH hPrevBrush = SelectObject( hDC, - GetStockObject(NULL_BRUSH) ); - - Rectangle( hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1 ); - SelectObject( hDC, hPrevBrush ); - SelectObject( hDC, hPrevPen ); - } else { - TEXTMETRIC tm; - rcFrame = rc; - - if (infoPtr->hFont) - SelectObject (hDC, infoPtr->hFont); - GetTextMetricsA (hDC, &tm); - rcFrame.top += (tm.tmHeight / 2) - 1; - DrawEdge (hDC, &rcFrame, EDGE_ETCHED, BF_RECT); - } - - if (wndPtr->text) - { - if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont ); - if (wndPtr->dwStyle & WS_DISABLED) - SetTextColor( hDC, GetSysColor(COLOR_GRAYTEXT) ); - rc.left += 10; - DrawTextA( hDC, wndPtr->text, -1, &rc, DT_SINGLELINE | DT_NOCLIP ); - } -} - - -/********************************************************************** - * User Button Functions - */ - -static void UB_Paint( WND *wndPtr, HDC hDC, WORD action ) -{ - RECT rc; - HBRUSH hBrush; - BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra; - - if (action == ODA_SELECT) return; - - GetClientRect( wndPtr->hwndSelf, &rc); - - if (infoPtr->hFont) SelectObject( hDC, infoPtr->hFont ); - hBrush = GetControlBrush( wndPtr->hwndSelf, hDC, CTLCOLOR_BTN ); - - FillRect( hDC, &rc, hBrush ); - if ((action == ODA_FOCUS) || - ((action == ODA_DRAWENTIRE) && (infoPtr->state & BUTTON_HASFOCUS))) - DrawFocusRect( hDC, &rc ); -} - - -/********************************************************************** - * Ownerdrawn Button Functions - */ - -static void OB_Paint( WND *wndPtr, HDC hDC, WORD action ) -{ - BUTTONINFO *infoPtr = (BUTTONINFO *)wndPtr->wExtra; - DRAWITEMSTRUCT dis; - - dis.CtlType = ODT_BUTTON; - dis.CtlID = wndPtr->wIDmenu; - dis.itemID = 0; - dis.itemAction = action; - dis.itemState = ((infoPtr->state & BUTTON_HASFOCUS) ? ODS_FOCUS : 0) | - ((infoPtr->state & BUTTON_HIGHLIGHTED) ? ODS_SELECTED : 0) | - ((wndPtr->dwStyle & WS_DISABLED) ? ODS_DISABLED : 0); - dis.hwndItem = wndPtr->hwndSelf; - dis.hDC = hDC; - dis.itemData = 0; - GetClientRect( wndPtr->hwndSelf, &dis.rcItem ); - SendMessageA( GetParent(wndPtr->hwndSelf), WM_DRAWITEM, - wndPtr->wIDmenu, (LPARAM)&dis ); -} diff --git a/reactos/lib/user32/controls/combo.c b/reactos/lib/user32/controls/combo.c deleted file mode 100644 index 0eea751203f..00000000000 --- a/reactos/lib/user32/controls/combo.c +++ /dev/null @@ -1,1570 +0,0 @@ -/* - * Combo controls - * - * Copyright 1997 Alex Korobka - * - * FIXME: roll up in Netscape 3.01. - */ - -#include - -#include -#include -#include - -#include -#include -#include - - /* bits in the dwKeyData */ -#define KEYDATA_ALT 0x2000 -#define KEYDATA_PREVSTATE 0x4000 - -/* - * Additional combo box definitions - */ - -#define CB_GETPTR( wnd ) (*(LPHEADCOMBO*)((wnd)->wExtra)) -#define CB_NOTIFY( lphc, code ) \ - (SendMessageA( (lphc)->owner, WM_COMMAND, \ - MAKEWPARAM((lphc)->self->wIDmenu, (code)), (LPARAM)(lphc)->self->hwndSelf)) -#define CB_GETEDITTEXTLENGTH( lphc ) \ - (SendMessageA( (lphc)->hWndEdit, WM_GETTEXTLENGTH, 0, 0 )) - -static HBITMAP hComboBmp = 0; -static UINT CBitHeight, CBitWidth; -static UINT CBitOffset = 8; - -/*********************************************************************** - * COMBO_Init - * - * Load combo button bitmap. - */ -WINBOOL COMBO_Init(void) -{ - HDC hDC; - - if( hComboBmp ) return TRUE; - if( (hDC = CreateCompatibleDC(0)) ) - { - WINBOOL bRet = FALSE; - if( (hComboBmp = LoadBitmap(0, MAKEINTRESOURCE(OBM_COMBO))) ) - { - BITMAP bm; - HBITMAP hPrevB; - RECT r; - - GetObjectA( hComboBmp, sizeof(bm), &bm ); - CBitHeight = bm.bmHeight; - CBitWidth = bm.bmWidth; - - DPRINT( "combo bitmap [%i,%i]\n", CBitWidth, CBitHeight ); - - hPrevB = SelectObject( hDC, hComboBmp); - SetRect( &r, 0, 0, CBitWidth, CBitHeight ); - InvertRect( hDC, &r ); - SelectObject( hDC, hPrevB ); - bRet = TRUE; - } - DeleteDC( hDC ); - return bRet; - } - return FALSE; -} - -/*********************************************************************** - * COMBO_NCCreate - */ -static LRESULT COMBO_NCCreate(WND* wnd, LPARAM lParam) -{ - LPHEADCOMBO lphc; - - if ( wnd && COMBO_Init() && - (lphc = HeapAlloc(GetProcessHeap(), 0, sizeof(HEADCOMBO))) ) - { - LPCREATESTRUCT lpcs = (CREATESTRUCT*)lParam; - - memset( lphc, 0, sizeof(HEADCOMBO) ); - *(LPHEADCOMBO*)wnd->wExtra = lphc; - - /* some braindead apps do try to use scrollbar/border flags */ - - lphc->dwStyle = (lpcs->style & ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL)); - wnd->dwStyle &= ~(WS_BORDER | WS_HSCROLL | WS_VSCROLL); - - if( !(lpcs->style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ) - lphc->dwStyle |= CBS_HASSTRINGS; - if( !(wnd->dwExStyle & WS_EX_NOPARENTNOTIFY) ) - lphc->wState |= CBF_NOTIFY; - - DPRINT( "[0x%08x], style = %08x\n", - (UINT)lphc, lphc->dwStyle ); - - return (LRESULT)(UINT)wnd->hwndSelf; - } - return (LRESULT)FALSE; -} - -/*********************************************************************** - * COMBO_NCDestroy - */ -static LRESULT COMBO_NCDestroy( LPHEADCOMBO lphc ) -{ - - if( lphc ) - { - WND* wnd = lphc->self; - - DPRINT("[%04x]: freeing storage\n", CB_HWND(lphc)); - - if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && lphc->hWndLBox ) - DestroyWindow( lphc->hWndLBox ); - - HeapFree( GetProcessHeap(), 0, lphc ); - wnd->wExtra[0] = 0; - } - return 0; -} - -/*********************************************************************** - * CBGetDefaultTextHeight - */ -static void CBGetDefaultTextHeight( LPHEADCOMBO lphc, LPSIZE lpSize ) -{ - if( lphc->editHeight ) /* explicitly set height */ - lpSize->cy = lphc->editHeight; - else - { - HDC hDC = GetDC( lphc->self->hwndSelf ); - HFONT hPrevFont = 0; - - if( lphc->hFont ) hPrevFont = SelectObject( hDC, lphc->hFont ); - - GetTextExtentPointA( hDC, "0", 1, lpSize); - - lpSize->cy += lpSize->cy / 4 + 4 * SYSMETRICS_CYBORDER; - - if( hPrevFont ) SelectObject( hDC, hPrevFont ); - ReleaseDC( lphc->self->hwndSelf, hDC ); - } - lpSize->cx = lphc->RectCombo.right - lphc->RectCombo.left; -} - - -/*********************************************************************** - * CBCalcPlacement - * - * Set up component coordinates given valid lphc->RectCombo. - */ -static void CBCalcPlacement( LPHEADCOMBO lphc, LPRECT lprEdit, - LPRECT lprButton, LPRECT lprLB ) -{ - RECT rect = lphc->RectCombo; - SIZE size; - - /* get combo height and width */ - - if( CB_OWNERDRAWN(lphc) ) - { - UINT u = lphc->RectEdit.bottom - lphc->RectEdit.top; - - if( lphc->wState & CBF_MEASUREITEM ) /* first initialization */ - { - MEASUREITEMSTRUCT mi; - - /* calculate defaults before sending WM_MEASUREITEM */ - - CBGetDefaultTextHeight( lphc, &size ); - - lphc->wState &= ~CBF_MEASUREITEM; - - mi.CtlType = ODT_COMBOBOX; - mi.CtlID = lphc->self->wIDmenu; - mi.itemID = -1; - mi.itemWidth = size.cx; - mi.itemHeight = size.cy - 6; /* ownerdrawn cb is taller */ - mi.itemData = 0; - SendMessageA(lphc->owner, WM_MEASUREITEM, - (WPARAM)mi.CtlID, (LPARAM)&mi); - u = 6 + (UINT)mi.itemHeight; - } - else - size.cx = rect.right - rect.left; - size.cy = u; - } - else - CBGetDefaultTextHeight( lphc, &size ); - - /* calculate text and button placement */ - - lprEdit->left = lprEdit->top = lprButton->top = 0; - if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* no button */ - lprButton->left = lprButton->right = lprButton->bottom = 0; - else - { - INT i = size.cx - CBitWidth - 10; /* seems ok */ - - lprButton->right = size.cx; - lprButton->left = (INT)i; - lprButton->bottom = lprButton->top + size.cy; - - if( i < 0 ) size.cx = 0; - else size.cx = i; - } - - if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) - { - size.cx -= CBitOffset; - if( size.cx < 0 ) size.cx = 0; - } - - lprEdit->right = size.cx; lprEdit->bottom = size.cy; - - /* listbox placement */ - - lprLB->left = ( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST ) ? 0 : CBitOffset; - lprLB->top = lprEdit->bottom - SYSMETRICS_CYBORDER; - lprLB->right = rect.right - rect.left; - lprLB->bottom = rect.bottom - rect.top; - - if( lphc->droppedWidth > (lprLB->right - lprLB->left) ) - lprLB->right = lprLB->left + lphc->droppedWidth; - - DPRINT("[%04x]: (%i,%i-%i,%i) placement\n", - CB_HWND(lphc), lphc->RectCombo.left, lphc->RectCombo.top, - lphc->RectCombo.right, lphc->RectCombo.bottom); - - DPRINT("\ttext\t= (%i,%i-%i,%i)\n", - lprEdit->left, lprEdit->top, lprEdit->right, lprEdit->bottom); - - DPRINT("\tbutton\t= (%i,%i-%i,%i)\n", - lprButton->left, lprButton->top, lprButton->right, lprButton->bottom); - - DPRINT("\tlbox\t= (%i,%i-%i,%i)\n", - lprLB->left, lprLB->top, lprLB->right, lprLB->bottom ); -} - -/*********************************************************************** - * CBGetDroppedControlRect - */ -static void CBGetDroppedControlRect( LPHEADCOMBO lphc, LPRECT lpRect) -{ - lpRect->left = lphc->RectCombo.left + - (lphc->wState & CBF_EDIT) ? CBitOffset : 0; - lpRect->top = lphc->RectCombo.top + lphc->RectEdit.bottom - - SYSMETRICS_CYBORDER; - lpRect->right = lphc->RectCombo.right; - lpRect->bottom = lphc->RectCombo.bottom - SYSMETRICS_CYBORDER; -} - -/*********************************************************************** - * COMBO_Create - */ -LRESULT COMBO_Create( LPHEADCOMBO lphc, WND* wnd, LPARAM lParam) -{ - static char clbName[] = "ComboLBox"; - static char editName[] = "Edit"; - - LPCREATESTRUCT lpcs = (CREATESTRUCT*)lParam; - - if( !CB_GETTYPE(lphc) ) lphc->dwStyle |= CBS_SIMPLE; - else if( CB_GETTYPE(lphc) != CBS_DROPDOWNLIST ) lphc->wState |= CBF_EDIT; - - lphc->self = wnd; - lphc->owner = lpcs->hwndParent; - - /* M$ IE 3.01 actually creates (and rapidly destroys) an ownerless combobox */ - - if( lphc->owner || !(lpcs->style & WS_VISIBLE) ) - { - UINT lbeStyle; - RECT editRect, btnRect, lbRect; - - GetWindowRect( wnd->hwndSelf, &lphc->RectCombo ); - - lphc->wState |= CBF_MEASUREITEM; - CBCalcPlacement( lphc, &editRect, &btnRect, &lbRect ); - lphc->RectButton = btnRect; - lphc->droppedWidth = lphc->editHeight = 0; - - /* create listbox popup */ - - lbeStyle = (LBS_NOTIFY | WS_BORDER | WS_CLIPSIBLINGS) | - (lpcs->style & (WS_VSCROLL | CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)); - - if( lphc->dwStyle & CBS_SORT ) - lbeStyle |= LBS_SORT; - if( lphc->dwStyle & CBS_HASSTRINGS ) - lbeStyle |= LBS_HASSTRINGS; - if( lphc->dwStyle & CBS_NOINTEGRALHEIGHT ) - lbeStyle |= LBS_NOINTEGRALHEIGHT; - if( lphc->dwStyle & CBS_DISABLENOSCROLL ) - lbeStyle |= LBS_DISABLENOSCROLL; - - if( CB_GETTYPE(lphc) == CBS_SIMPLE ) /* child listbox */ - lbeStyle |= WS_CHILD | WS_VISIBLE; - else /* popup listbox */ - { - lbeStyle |= WS_POPUP; - OffsetRect( &lbRect, lphc->RectCombo.left, lphc->RectCombo.top ); - } - - /* Dropdown ComboLBox is not a child window and we cannot pass - * ID_CB_LISTBOX directly because it will be treated as a menu handle. - */ - - lphc->hWndLBox = CreateWindowExA( 0, clbName, NULL, lbeStyle, - lbRect.left + SYSMETRICS_CXBORDER, - lbRect.top + SYSMETRICS_CYBORDER, - lbRect.right - lbRect.left - 2 * SYSMETRICS_CXBORDER, - lbRect.bottom - lbRect.top - 2 * SYSMETRICS_CYBORDER, - lphc->self->hwndSelf, - (lphc->dwStyle & CBS_DROPDOWN)? (HMENU)0 : (HMENU)ID_CB_LISTBOX, - lphc->self->hInstance, (LPVOID)lphc ); - if( lphc->hWndLBox ) - { - WINBOOL bEdit = TRUE; - lbeStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NOHIDESEL | ES_LEFT; - if( lphc->wState & CBF_EDIT ) - { - if( lphc->dwStyle & CBS_OEMCONVERT ) - lbeStyle |= ES_OEMCONVERT; - if( lphc->dwStyle & CBS_AUTOHSCROLL ) - lbeStyle |= ES_AUTOHSCROLL; - if( lphc->dwStyle & CBS_LOWERCASE ) - lbeStyle |= ES_LOWERCASE; - else if( lphc->dwStyle & CBS_UPPERCASE ) - lbeStyle |= ES_UPPERCASE; - lphc->hWndEdit = CreateWindowExA( 0, editName, NULL, lbeStyle, - editRect.left, editRect.top, editRect.right - editRect.left, - editRect.bottom - editRect.top, lphc->self->hwndSelf, - (HMENU)ID_CB_EDIT, lphc->self->hInstance, NULL ); - if( !lphc->hWndEdit ) bEdit = FALSE; - } - - if( bEdit ) - { - lphc->RectEdit = editRect; - if( CB_GETTYPE(lphc) != CBS_SIMPLE ) - { - lphc->wState |= CBF_NORESIZE; - SetWindowPos( wnd->hwndSelf, 0, 0, 0, - lphc->RectCombo.right - lphc->RectCombo.left, - lphc->RectEdit.bottom - lphc->RectEdit.top, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ); - lphc->wState &= ~CBF_NORESIZE; - } - DPRINT("init done\n"); - return (LRESULT)wnd->hwndSelf; - } - DPRINT("edit control failure.\n"); - } else DPRINT("listbox failure.\n"); - } else DPRINT("no owner for visible combo.\n"); - - /* CreateWindow() will send WM_NCDESTROY to cleanup */ - - return -1; -} - -/*********************************************************************** - * CBPaintButton - * - * Paint combo button (normal, pressed, and disabled states). - */ -static void CBPaintButton(LPHEADCOMBO lphc, HDC hdc) -{ - RECT r; - UINT x, y; - WINBOOL bWINBOOL; - HDC hMemDC; - HBRUSH hPrevBrush; - COLORREF oldTextColor, oldBkColor; - - if( lphc->wState & CBF_NOREDRAW ) return; - - hPrevBrush = SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE)); - r = lphc->RectButton; - - Rectangle(hdc, r.left, r.top, r.right, r.bottom ); - if( (bWINBOOL = lphc->wState & CBF_BUTTONDOWN) ) - { - DrawEdge( hdc, &r, EDGE_SUNKEN, BF_RECT ); - OffsetRect( &r, 1, 1 ); - } else { - r.top++, r.left++; - DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT ); - r.top--, r.left--; - } - - InflateRect( &r, -1, -1 ); - - x = (r.left + r.right - CBitWidth) >> 1; - y = (r.top + r.bottom - CBitHeight) >> 1; - - InflateRect( &r, -3, -3 ); - - hMemDC = CreateCompatibleDC( hdc ); - SelectObject( hMemDC, hComboBmp ); - oldTextColor = SetTextColor( hdc, GetSysColor(COLOR_BTNFACE) ); - oldBkColor = SetBkColor( hdc, CB_DISABLED(lphc) ? RGB(128,128,128) : - RGB(0,0,0) ); - BitBlt( hdc, x, y, 8, 8, hMemDC, 0, 0, SRCCOPY ); - SetBkColor( hdc, oldBkColor ); - SetTextColor( hdc, oldTextColor ); - DeleteDC( hMemDC ); - SelectObject( hdc, hPrevBrush ); -} - -/*********************************************************************** - * CBPaintText - * - * Paint CBS_DROPDOWNLIST text field / update edit control contents. - */ -static void CBPaintText(LPHEADCOMBO lphc, HDC hdc) -{ - INT id, size = 0; - LPSTR pText = NULL; - - if( lphc->wState & CBF_NOREDRAW ) return; - - /* follow Windows combobox that sends a bunch of text - * inquiries to its listbox while processing WM_PAINT. */ - - if( (id = SendMessageA(lphc->hWndLBox, LB_GETCURSEL, 0, 0) ) != LB_ERR ) - { - size = SendMessageA( lphc->hWndLBox, LB_GETTEXTLEN, id, 0); - if( (pText = HeapAlloc( GetProcessHeap(), 0, size + 1)) ) - { - SendMessageA( lphc->hWndLBox, LB_GETTEXT, (WPARAM)id, (LPARAM)pText ); - pText[size] = '\0'; /* just in case */ - } else return; - } - - if( lphc->wState & CBF_EDIT ) - { - if( CB_HASSTRINGS(lphc) ) SetWindowTextA( lphc->hWndEdit, pText ? pText : "" ); - if( lphc->wState & CBF_FOCUSED ) - SendMessageA( lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1)); - } - else /* paint text field ourselves */ - { - HBRUSH hPrevBrush = 0; - HDC hDC = hdc; - - if( !hDC ) - { - if ((hDC = GetDC(lphc->self->hwndSelf))) - { - HBRUSH hBrush = (HBRUSH)SendMessageA( lphc->owner, - WM_CTLCOLORLISTBOX, - (WPARAM)hDC, (LPARAM)lphc->self->hwndSelf ); - hPrevBrush = SelectObject( hDC, - (hBrush) ? hBrush : GetStockObject(WHITE_BRUSH) ); - } - } - if( hDC ) - { - RECT rect; - UINT itemState; - HFONT hPrevFont = (lphc->hFont) ? SelectObject(hDC, lphc->hFont) : 0; - - PatBlt( hDC, (rect.left = lphc->RectEdit.left + SYSMETRICS_CXBORDER), - (rect.top = lphc->RectEdit.top + SYSMETRICS_CYBORDER), - (rect.right = lphc->RectEdit.right - SYSMETRICS_CXBORDER), - (rect.bottom = lphc->RectEdit.bottom - SYSMETRICS_CYBORDER) - 1, PATCOPY ); - InflateRect( &rect, -1, -1 ); - - if( lphc->wState & CBF_FOCUSED && - !(lphc->wState & CBF_DROPPED) ) - { - /* highlight */ - - FillRect( hDC, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) ); - SetBkColor( hDC, GetSysColor( COLOR_HIGHLIGHT ) ); - SetTextColor( hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); - itemState = ODS_SELECTED | ODS_FOCUS; - } else itemState = 0; - - if( CB_OWNERDRAWN(lphc) ) - { - DRAWITEMSTRUCT dis; - - if( lphc->self->dwStyle & WS_DISABLED ) itemState |= ODS_DISABLED; - - dis.CtlType = ODT_COMBOBOX; - dis.CtlID = lphc->self->wIDmenu; - dis.hwndItem = lphc->self->hwndSelf; - dis.itemAction = ODA_DRAWENTIRE; - dis.itemID = id; - dis.itemState = itemState; - dis.hDC = hDC; - dis.rcItem = rect; - dis.itemData = SendMessageA( lphc->hWndLBox, LB_GETITEMDATA, - (WPARAM)id, 0 ); - SendMessageA( lphc->owner, WM_DRAWITEM, - lphc->self->wIDmenu, (LPARAM)&dis ); - } - else - { - ExtTextOutA( hDC, rect.left + 1, rect.top + 1, - ETO_OPAQUE | ETO_CLIPPED, &rect, - pText ? pText : "" , size, NULL ); - if(lphc->wState & CBF_FOCUSED && !(lphc->wState & CBF_DROPPED)) - DrawFocusRect( hDC, &rect ); - } - - if( hPrevFont ) SelectObject(hDC, hPrevFont ); - if( !hdc ) - { - if( hPrevBrush ) SelectObject( hDC, hPrevBrush ); - ReleaseDC( lphc->self->hwndSelf, hDC ); - } - } - } - if (pText) - HeapFree( GetProcessHeap(), 0, pText ); -} - -/*********************************************************************** - * COMBO_Paint - */ -static LRESULT COMBO_Paint(LPHEADCOMBO lphc, HDC hParamDC) -{ - PAINTSTRUCT ps; - HDC hDC; - - hDC = (hParamDC) ? hParamDC - : BeginPaint( lphc->self->hwndSelf, &ps); - if( hDC && !(lphc->wState & CBF_NOREDRAW) ) - { - HBRUSH hPrevBrush, hBkgBrush; - - hBkgBrush = (HBRUSH)SendMessageA( lphc->owner, WM_CTLCOLORLISTBOX, - (WPARAM)hDC, (LPARAM)lphc->self->hwndSelf ); - if( !hBkgBrush ) hBkgBrush = GetStockObject(WHITE_BRUSH); - - hPrevBrush = SelectObject( hDC, hBkgBrush ); - if( !IsRectEmpty(&lphc->RectButton) ) - { - /* paint everything to the right of the text field */ - - PatBlt( hDC, lphc->RectEdit.right, lphc->RectEdit.top, - lphc->RectButton.right - lphc->RectEdit.right, - lphc->RectEdit.bottom - lphc->RectEdit.top, PATCOPY ); - CBPaintButton( lphc, hDC ); - } - - if( !(lphc->wState & CBF_EDIT) ) - { - /* paint text field */ - - HPEN hPrevPen = SelectObject( hDC, GetSysColorPen( - COLOR_WINDOWFRAME) ); - - Rectangle( hDC, lphc->RectEdit.left, lphc->RectEdit.top, - lphc->RectEdit.right, lphc->RectButton.bottom ); - SelectObject( hDC, hPrevPen ); - CBPaintText( lphc, hDC ); - } - if( hPrevBrush ) SelectObject( hDC, hPrevBrush ); - } - if( !hParamDC ) EndPaint(lphc->self->hwndSelf, &ps); - return 0; -} - -/*********************************************************************** - * CBUpdateLBox - * - * Select listbox entry according to the contents of the edit control. - */ -static INT CBUpdateLBox( LPHEADCOMBO lphc ) -{ - INT length, idx, ret; - LPSTR pText = NULL; - - idx = ret = LB_ERR; - length = CB_GETEDITTEXTLENGTH( lphc ); - - if( length > 0 ) - pText = (LPSTR) HeapAlloc( GetProcessHeap(), 0, length + 1); - - DPRINT("\t edit text length %i\n", length ); - - if( pText ) - { - if( length ) GetWindowTextA( lphc->hWndEdit, pText, length + 1); - else pText[0] = '\0'; - idx = SendMessageA( lphc->hWndLBox, LB_FINDSTRING, - (WPARAM)(-1), (LPARAM)pText ); - if( idx == LB_ERR ) idx = 0; /* select first item */ - else ret = idx; - HeapFree( GetProcessHeap(), 0, pText ); - } - - /* select entry */ - - SendMessageA( lphc->hWndLBox, LB_SETCURSEL, (WPARAM)idx, 0 ); - - if( idx >= 0 ) - { - SendMessageA( lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)idx, 0 ); - /* probably superfluous but Windows sends this too */ - SendMessageA( lphc->hWndLBox, LB_SETCARETINDEX, (WPARAM)idx, 0 ); - } - return ret; -} - -/*********************************************************************** - * CBUpdateEdit - * - * Copy a listbox entry to the edit control. - */ -static void CBUpdateEdit( LPHEADCOMBO lphc , INT index ) -{ - INT length; - LPSTR pText = NULL; - - DPRINT("\t %i\n", index ); - - if( index == -1 ) - { - length = CB_GETEDITTEXTLENGTH( lphc ); - if( length ) - { - if( (pText = (LPSTR) HeapAlloc( GetProcessHeap(), 0, length + 1)) ) - { - GetWindowTextA( lphc->hWndEdit, pText, length + 1 ); - index = SendMessageA( lphc->hWndLBox, LB_FINDSTRING, - (WPARAM)(-1), (LPARAM)pText ); - HeapFree( GetProcessHeap(), 0, pText ); - } - } - } - - if( index >= 0 ) /* got an entry */ - { - length = SendMessageA( lphc->hWndLBox, LB_GETTEXTLEN, (WPARAM)index, 0); - if( length ) - { - if( (pText = (LPSTR) HeapAlloc( GetProcessHeap(), 0, length + 1)) ) - { - SendMessageA( lphc->hWndLBox, LB_GETTEXT, - (WPARAM)index, (LPARAM)pText ); - SendMessageA( lphc->hWndEdit, WM_SETTEXT, 0, (LPARAM)pText ); - SendMessageA( lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1) ); - HeapFree( GetProcessHeap(), 0, pText ); - } - } - } -} - -/*********************************************************************** - * CBDropDown - * - * Show listbox popup. - */ -static void CBDropDown( LPHEADCOMBO lphc ) -{ - INT index; - RECT rect; - LPRECT pRect = NULL; - - DPRINT("[%04x]: drop down\n", CB_HWND(lphc)); - - CB_NOTIFY( lphc, CBN_DROPDOWN ); - - /* set selection */ - - lphc->wState |= CBF_DROPPED; - if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) - { - index = CBUpdateLBox( lphc ); - if( !(lphc->wState & CBF_CAPTURE) ) CBUpdateEdit( lphc, index ); - } - else - { - index = SendMessageA( lphc->hWndLBox, LB_GETCURSEL, 0, 0 ); - if( index == LB_ERR ) index = 0; - SendMessageA( lphc->hWndLBox, LB_SETTOPINDEX, (WPARAM)index, 0 ); - SendMessageA( lphc->hWndLBox, LB_CARETON, 0, 0 ); - pRect = &lphc->RectEdit; - } - - /* now set popup position */ - - GetWindowRect( lphc->self->hwndSelf, &rect ); - - rect.top += lphc->RectEdit.bottom - lphc->RectEdit.top - SYSMETRICS_CYBORDER; - rect.bottom = rect.top + lphc->RectCombo.bottom - - lphc->RectCombo.top - SYSMETRICS_CYBORDER; - rect.right = rect.left + lphc->RectCombo.right - lphc->RectCombo.left; - rect.left += ( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST ) ? 0 : CBitOffset; - - SetWindowPos( lphc->hWndLBox, HWND_TOP, rect.left, rect.top, - rect.right - rect.left, rect.bottom - rect.top, - SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOREDRAW); - - if( !(lphc->wState & CBF_NOREDRAW) ) - if( pRect ) - RedrawWindow( lphc->self->hwndSelf, pRect, 0, RDW_INVALIDATE | - RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN ); - ShowWindow( lphc->hWndLBox, SW_SHOWNA ); -} - -/*********************************************************************** - * CBRollUp - * - * Hide listbox popup. - */ -static void CBRollUp( LPHEADCOMBO lphc, WINBOOL ok, WINBOOL bButton ) -{ - HWND hWnd = lphc->self->hwndSelf; - - CB_NOTIFY( lphc, (ok) ? CBN_SELENDOK : CBN_SELENDCANCEL ); - - if( IsWindow( hWnd ) && CB_GETTYPE(lphc) != CBS_SIMPLE ) - { - - DPRINT("[%04x]: roll up [%i]\n", CB_HWND(lphc), (INT)ok ); - - /* always send WM_LBUTTONUP? */ - SendMessageA( lphc->hWndLBox, WM_LBUTTONUP, 0, (LPARAM)(-1) ); - - if( lphc->wState & CBF_DROPPED ) - { - RECT rect; - - lphc->wState &= ~CBF_DROPPED; - ShowWindow( lphc->hWndLBox, SW_HIDE ); - - if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) - { - INT index = SendMessageA( lphc->hWndLBox, LB_GETCURSEL, 0, 0 ); - CBUpdateEdit( lphc, index ); - rect = lphc->RectButton; - } - else - { - if( bButton ) - UnionRect( &rect, &lphc->RectButton, - &lphc->RectEdit ); - else - rect = lphc->RectEdit; - bButton = TRUE; - } - - if( bButton && !(lphc->wState & CBF_NOREDRAW) ) - RedrawWindow( hWnd, &rect, 0, RDW_INVALIDATE | - RDW_ERASE | RDW_UPDATENOW | RDW_NOCHILDREN ); - CB_NOTIFY( lphc, CBN_CLOSEUP ); - } - } -} - -/*********************************************************************** - * COMBO_FlipListbox - * - * Used by the ComboLBox to show/hide itself in response to VK_F4, etc... - */ -WINBOOL COMBO_FlipListbox( LPHEADCOMBO lphc, WINBOOL bRedrawButton ) -{ - if( lphc->wState & CBF_DROPPED ) - { - CBRollUp( lphc, TRUE, bRedrawButton ); - return FALSE; - } - - CBDropDown( lphc ); - return TRUE; -} - -/*********************************************************************** - * COMBO_GetLBWindow - * - * Edit control helper. - */ -HWND COMBO_GetLBWindow( WND* pWnd ) -{ - LPHEADCOMBO lphc = CB_GETPTR(pWnd); - if( lphc ) return lphc->hWndLBox; - return 0; -} - - -/*********************************************************************** - * CBRepaintButton - */ -static void CBRepaintButton( LPHEADCOMBO lphc ) -{ - HDC hDC = GetDC( lphc->self->hwndSelf ); - - if( hDC ) - { - CBPaintButton( lphc, hDC ); - ReleaseDC( lphc->self->hwndSelf, hDC ); - } -} - -/*********************************************************************** - * COMBO_SetFocus - */ -static void COMBO_SetFocus( LPHEADCOMBO lphc ) -{ - if( !(lphc->wState & CBF_FOCUSED) ) - { - if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST ) - SendMessageA( lphc->hWndLBox, LB_CARETON, 0, 0 ); - - if( lphc->wState & CBF_EDIT ) - SendMessageA( lphc->hWndEdit, EM_SETSEL, 0, (LPARAM)(-1) ); - lphc->wState |= CBF_FOCUSED; - if( !(lphc->wState & CBF_EDIT) ) CBPaintText( lphc, 0 ); - - CB_NOTIFY( lphc, CBN_SETFOCUS ); - } -} - -/*********************************************************************** - * COMBO_KillFocus - */ -static void COMBO_KillFocus( LPHEADCOMBO lphc ) -{ - HWND hWnd = lphc->self->hwndSelf; - - if( lphc->wState & CBF_FOCUSED ) - { - SendMessageA( hWnd, WM_LBUTTONUP, 0, (LPARAM)(-1) ); - - CBRollUp( lphc, FALSE, TRUE ); - if( IsWindow( hWnd ) ) - { - if( CB_GETTYPE(lphc) == CBS_DROPDOWNLIST ) - SendMessageA( lphc->hWndLBox, LB_CARETOFF, 0, 0 ); - - lphc->wState &= ~CBF_FOCUSED; - - /* redraw text */ - if( lphc->wState & CBF_EDIT ) - SendMessageA( lphc->hWndEdit, EM_SETSEL, (WPARAM)(-1), 0 ); - else CBPaintText( lphc, 0 ); - - CB_NOTIFY( lphc, CBN_KILLFOCUS ); - } - } -} - -/*********************************************************************** - * COMBO_Command - */ -static LRESULT COMBO_Command( LPHEADCOMBO lphc, WPARAM wParam, HWND hWnd ) -{ - if( lphc->wState & CBF_EDIT && lphc->hWndEdit == hWnd ) - { - /* ">> 8" makes gcc generate jump-table instead of cmp ladder */ - - switch( HIWORD(wParam) >> 8 ) - { - case (EN_SETFOCUS >> 8): - - DPRINT("[%04x]: edit [%04x] got focus\n", - CB_HWND(lphc), lphc->hWndEdit ); - - if( !(lphc->wState & CBF_FOCUSED) ) COMBO_SetFocus( lphc ); - break; - - case (EN_KILLFOCUS >> 8): - - DPRINT("[%04x]: edit [%04x] lost focus\n", - CB_HWND(lphc), lphc->hWndEdit ); - - /* NOTE: it seems that Windows' edit control sends an - * undocumented message WM_USER + 0x1B instead of this - * notification (only when it happens to be a part of - * the combo). ?? - AK. - */ - - COMBO_KillFocus( lphc ); - break; - - - case (EN_CHANGE >> 8): - CB_NOTIFY( lphc, CBN_EDITCHANGE ); - CBUpdateLBox( lphc ); - break; - - case (EN_UPDATE >> 8): - CB_NOTIFY( lphc, CBN_EDITUPDATE ); - break; - - case (EN_ERRSPACE >> 8): - CB_NOTIFY( lphc, CBN_ERRSPACE ); - } - } - else if( lphc->hWndLBox == hWnd ) - { - switch( HIWORD(wParam) ) - { - case LBN_ERRSPACE: - CB_NOTIFY( lphc, CBN_ERRSPACE ); - break; - - case LBN_DBLCLK: - CB_NOTIFY( lphc, CBN_DBLCLK ); - break; - - case LBN_SELCHANGE: - case LBN_SELCANCEL: - - DPRINT("[%04x]: lbox selection change [%04x]\n", - CB_HWND(lphc), lphc->wState ); - - /* do not roll up if selection is being tracked - * by arrowkeys in the dropdown listbox */ - - if( (lphc->wState & CBF_DROPPED) && !(lphc->wState & CBF_NOROLLUP) ) - CBRollUp( lphc, (HIWORD(wParam) == LBN_SELCHANGE), TRUE ); - else lphc->wState &= ~CBF_NOROLLUP; - - CB_NOTIFY( lphc, CBN_SELCHANGE ); - CBPaintText( lphc, 0 ); - /* fall through */ - - case LBN_SETFOCUS: - case LBN_KILLFOCUS: - /* nothing to do here since ComboLBox always resets the focus to its - * combo/edit counterpart */ - break; - } - } - return 0; -} - -/*********************************************************************** - * COMBO_ItemOp - * - * Fixup an ownerdrawn item operation and pass it up to the combobox owner. - */ -static LRESULT COMBO_ItemOp( LPHEADCOMBO lphc, UINT msg, - WPARAM wParam, LPARAM lParam ) -{ - HWND hWnd = lphc->self->hwndSelf; - - DPRINT("[%04x]: ownerdraw op %04x\n", CB_HWND(lphc), msg ); - -#define lpIS ((LPDELETEITEMSTRUCT)lParam) - - /* two first items are the same in all 4 structs */ - lpIS->CtlType = ODT_COMBOBOX; - lpIS->CtlID = lphc->self->wIDmenu; - - switch( msg ) /* patch window handle */ - { - case WM_DELETEITEM: - lpIS->hwndItem = hWnd; -#undef lpIS - break; - case WM_DRAWITEM: -#define lpIS ((LPDRAWITEMSTRUCT)lParam) - lpIS->hwndItem = hWnd; -#undef lpIS - break; - case WM_COMPAREITEM: -#define lpIS ((LPCOMPAREITEMSTRUCT)lParam) - lpIS->hwndItem = hWnd; -#undef lpIS - break; - } - - return SendMessageA( lphc->owner, msg, lphc->self->wIDmenu, lParam ); -} - -/*********************************************************************** - * COMBO_GetText - */ -static LRESULT COMBO_GetText( LPHEADCOMBO lphc, UINT N, LPSTR lpText) -{ - if( lphc->wState & CBF_EDIT ) - return SendMessageA( lphc->hWndEdit, WM_GETTEXT, - (WPARAM)N, (LPARAM)lpText ); - - /* get it from the listbox */ - - if( lphc->hWndLBox ) - { - INT idx = SendMessageA( lphc->hWndLBox, LB_GETCURSEL, 0, 0 ); - if( idx != LB_ERR ) - { - LPSTR lpBuffer; - INT length = SendMessageA( lphc->hWndLBox, LB_GETTEXTLEN, - (WPARAM)idx, 0 ); - - /* 'length' is without the terminating character */ - if( length >= N ) - lpBuffer = (LPSTR) HeapAlloc( GetProcessHeap(), 0, length + 1 ); - else - lpBuffer = lpText; - - if( lpBuffer ) - { - INT n = SendMessageA( lphc->hWndLBox, LB_GETTEXT, - (WPARAM)idx, (LPARAM)lpBuffer ); - - /* truncate if buffer is too short */ - - if( length >= N ) - { - if (N && lpText) { - if( n != LB_ERR ) memcpy( lpText, lpBuffer, (N>n) ? n+1 : N-1 ); - lpText[N - 1] = '\0'; - } - HeapFree( GetProcessHeap(), 0, lpBuffer ); - } - return (LRESULT)n; - } - } - } - return 0; -} - - -/*********************************************************************** - * CBResetPos - * - * This function sets window positions according to the updated - * component placement struct. - */ -static void CBResetPos( LPHEADCOMBO lphc, LPRECT lbRect, WINBOOL bRedraw ) -{ - WINBOOL bDrop = (CB_GETTYPE(lphc) != CBS_SIMPLE); - - /* NOTE: logs sometimes have WM_LBUTTONUP before a cascade of - * sizing messages */ - - if( lphc->wState & CBF_EDIT ) - SetWindowPos( lphc->hWndEdit, 0, lphc->RectEdit.left, lphc->RectEdit.top, - lphc->RectEdit.right - lphc->RectEdit.left, - lphc->RectEdit.bottom - lphc->RectEdit.top, - SWP_NOZORDER | SWP_NOACTIVATE | ((bDrop) ? SWP_NOREDRAW : 0) ); - - if( bDrop ) - OffsetRect( lbRect, lphc->RectCombo.left, lphc->RectCombo.top ); - - lbRect->right -= lbRect->left; /* convert to width */ - lbRect->bottom -= lbRect->top; - SetWindowPos( lphc->hWndLBox, 0, lbRect->left, lbRect->top, - lbRect->right, lbRect->bottom, - SWP_NOACTIVATE | SWP_NOZORDER | ((bDrop) ? SWP_NOREDRAW : 0) ); - - if( bDrop ) - { - if( lphc->wState & CBF_DROPPED ) - { - lphc->wState &= ~CBF_DROPPED; - ShowWindow( lphc->hWndLBox, SW_HIDE ); - } - - lphc->wState |= CBF_NORESIZE; - SetWindowPos( lphc->self->hwndSelf, 0, 0, 0, - lphc->RectCombo.right - lphc->RectCombo.left, - lphc->RectEdit.bottom - lphc->RectEdit.top, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW ); - lphc->wState &= ~CBF_NORESIZE; - - if( bRedraw && !(lphc->wState & CBF_NOREDRAW) ) - RedrawWindow( lphc->self->hwndSelf, NULL, 0, - RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW ); - } -} - - -/*********************************************************************** - * COMBO_Size - */ -static void COMBO_Size( LPHEADCOMBO lphc ) -{ - RECT rect; - INT w, h; - - GetWindowRect( lphc->self->hwndSelf, &rect ); - w = rect.right - rect.left; h = rect.bottom - rect.top; - - DPRINT("w = %i, h = %i\n", w, h ); - - /* CreateWindow() may send a bogus WM_SIZE, ignore it */ - - if( w == (lphc->RectCombo.right - lphc->RectCombo.left) ) - { - if( (CB_GETTYPE(lphc) == CBS_SIMPLE) && - (h == (lphc->RectCombo.bottom - lphc->RectCombo.top)) ) - return; - else if( (lphc->dwStyle & CBS_DROPDOWN) && - (h == (lphc->RectEdit.bottom - lphc->RectEdit.top)) ) - return; - } - lphc->RectCombo = rect; - CBCalcPlacement( lphc, &lphc->RectEdit, &lphc->RectButton, &rect ); - CBResetPos( lphc, &rect, TRUE ); -} - - -/*********************************************************************** - * COMBO_Font - */ -static void COMBO_Font( LPHEADCOMBO lphc, HFONT hFont, WINBOOL bRedraw ) -{ - RECT rect; - - lphc->hFont = hFont; - - if( lphc->wState & CBF_EDIT ) - SendMessageA( lphc->hWndEdit, WM_SETFONT, (WPARAM)hFont, bRedraw ); - SendMessageA( lphc->hWndLBox, WM_SETFONT, (WPARAM)hFont, bRedraw ); - - GetWindowRect( lphc->self->hwndSelf, &rect ); - OffsetRect( &lphc->RectCombo, rect.left - lphc->RectCombo.left, - rect.top - lphc->RectCombo.top ); - CBCalcPlacement( lphc, &lphc->RectEdit, - &lphc->RectButton, &rect ); - CBResetPos( lphc, &rect, bRedraw ); -} - - -/*********************************************************************** - * COMBO_SetItemHeight - */ -static LRESULT COMBO_SetItemHeight( LPHEADCOMBO lphc, INT index, INT height ) -{ - LRESULT lRet = CB_ERR; - - if( index == -1 ) /* set text field height */ - { - if( height < 768 ) - { - RECT rect; - - lphc->editHeight = height; - GetWindowRect( lphc->self->hwndSelf, &rect ); - OffsetRect( &lphc->RectCombo, rect.left - lphc->RectCombo.left, - rect.top - lphc->RectCombo.top ); - CBCalcPlacement( lphc, &lphc->RectEdit, - &lphc->RectButton, &rect ); - CBResetPos( lphc, &rect, TRUE ); - lRet = height; - } - } - else if ( CB_OWNERDRAWN(lphc) ) /* set listbox item height */ - lRet = SendMessageA( lphc->hWndLBox, LB_SETITEMHEIGHT, - (WPARAM)index, (LPARAM)height ); - return lRet; -} - -/*********************************************************************** - * COMBO_SelectString - */ -static LRESULT COMBO_SelectString( LPHEADCOMBO lphc, INT start, LPCSTR pText ) -{ - INT index = SendMessageA( lphc->hWndLBox, LB_SELECTSTRING, - (WPARAM)start, (LPARAM)pText ); - if( index >= 0 ) - { - if( lphc->wState & CBF_EDIT ) - CBUpdateEdit( lphc, index ); - else - CBPaintText( lphc, 0 ); - } - return (LRESULT)index; -} - -/*********************************************************************** - * COMBO_LButtonDown - */ -static void COMBO_LButtonDown( LPHEADCOMBO lphc, LPARAM lParam ) -{ - POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - WINBOOL bButton = PtInRect(&lphc->RectButton, pt); - HWND hWnd = lphc->self->hwndSelf; - - if( (CB_GETTYPE(lphc) == CBS_DROPDOWNLIST) || - (bButton && (CB_GETTYPE(lphc) == CBS_DROPDOWN)) ) - { - lphc->wState |= CBF_BUTTONDOWN; - if( lphc->wState & CBF_DROPPED ) - { - /* got a click to cancel selection */ - - CBRollUp( lphc, TRUE, FALSE ); - if( !IsWindow( hWnd ) ) return; - - if( lphc->wState & CBF_CAPTURE ) - { - lphc->wState &= ~CBF_CAPTURE; - ReleaseCapture(); - } - lphc->wState &= ~CBF_BUTTONDOWN; - } - else - { - /* drop down the listbox and start tracking */ - - lphc->wState |= CBF_CAPTURE; - CBDropDown( lphc ); - SetCapture( hWnd ); - } - if( bButton ) CBRepaintButton( lphc ); - } -} - -/*********************************************************************** - * COMBO_LButtonUp - * - * Release capture and stop tracking if needed. - */ -static void COMBO_LButtonUp( LPHEADCOMBO lphc, LPARAM lParam ) -{ - if( lphc->wState & CBF_CAPTURE ) - { - lphc->wState &= ~CBF_CAPTURE; - if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) - { - INT index = CBUpdateLBox( lphc ); - CBUpdateEdit( lphc, index ); - } - ReleaseCapture(); - } - - if( lphc->wState & CBF_BUTTONDOWN ) - { - lphc->wState &= ~CBF_BUTTONDOWN; - CBRepaintButton( lphc ); - } -} - -/*********************************************************************** - * COMBO_MouseMove - * - * Two things to do - track combo button and release capture when - * pointer goes into the listbox. - */ -static void COMBO_MouseMove( LPHEADCOMBO lphc, WPARAM wParam, LPARAM lParam ) -{ - POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - RECT lbRect; - - if( lphc->wState & CBF_BUTTONDOWN ) - { - WINBOOL bButton = PtInRect(&lphc->RectButton, pt); - - if( !bButton ) - { - lphc->wState &= ~CBF_BUTTONDOWN; - CBRepaintButton( lphc ); - } - } - - GetClientRect( lphc->hWndLBox, &lbRect ); - MapWindowPoints( lphc->self->hwndSelf, lphc->hWndLBox, &pt, 1 ); - if( PtInRect(&lbRect, pt) ) - { - lphc->wState &= ~CBF_CAPTURE; - ReleaseCapture(); - if( CB_GETTYPE(lphc) == CBS_DROPDOWN ) CBUpdateLBox( lphc ); - - /* hand over pointer tracking */ - SendMessageA( lphc->hWndLBox, WM_LBUTTONDOWN, wParam, lParam ); - } -} - - -/*********************************************************************** - * ComboWndProc - * - * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win/ctrl/src/combobox_15.htm - */ -LRESULT WINAPI ComboWndProc( HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam ) -{ - WND* pWnd = WIN_FindWndPtr(hwnd); - - if( pWnd ) - { - LPHEADCOMBO lphc = CB_GETPTR(pWnd); - - DPRINT( "[%04x]: msg %s wp %08x lp %08lx\n", - pWnd->hwndSelf, SPY_GetMsgName(message), wParam, lParam ); - - if( lphc || message == WM_NCCREATE ) - switch(message) - { - - /* System messages */ - - case WM_NCCREATE: - return COMBO_NCCreate(pWnd, lParam); - - case WM_NCDESTROY: - COMBO_NCDestroy(lphc); - break; - - case WM_CREATE: - return COMBO_Create(lphc, pWnd, lParam); - - case WM_PAINT: - /* wParam may contain a valid HDC! */ - return COMBO_Paint(lphc, wParam); - - case WM_ERASEBKGND: - return TRUE; - - case WM_GETDLGCODE: - return (LRESULT)(DLGC_WANTARROWS | DLGC_WANTCHARS); - - case WM_SIZE: - if( lphc->hWndLBox && - !(lphc->wState & CBF_NORESIZE) ) COMBO_Size( lphc ); - return TRUE; - - case WM_SETFONT: - COMBO_Font( lphc, (HFONT)wParam, (WINBOOL)lParam ); - return TRUE; - - case WM_GETFONT: - return (LRESULT)lphc->hFont; - - case WM_SETFOCUS: - if( lphc->wState & CBF_EDIT ) - SetFocus( lphc->hWndEdit ); - else - COMBO_SetFocus( lphc ); - return TRUE; - - case WM_KILLFOCUS: -#define hwndFocus ((HWND)wParam) - if( !hwndFocus || - (hwndFocus != lphc->hWndEdit && hwndFocus != lphc->hWndLBox )) - COMBO_KillFocus( lphc ); -#undef hwndFocus - return TRUE; - - case WM_COMMAND: - return COMBO_Command( lphc, wParam, (HWND)lParam ); - - case WM_GETTEXT: - return COMBO_GetText( lphc, (UINT)wParam, (LPSTR)lParam ); - - case WM_SETTEXT: - case WM_GETTEXTLENGTH: - case WM_CLEAR: - case WM_CUT: - case WM_PASTE: - case WM_COPY: - if( lphc->wState & CBF_EDIT ) - return SendMessageA( lphc->hWndEdit, message, wParam, lParam ); - return CB_ERR; - - case WM_DRAWITEM: - case WM_DELETEITEM: - case WM_COMPAREITEM: - case WM_MEASUREITEM: - return COMBO_ItemOp( lphc, message, wParam, lParam ); - - case WM_ENABLE: - if( lphc->wState & CBF_EDIT ) - EnableWindow( lphc->hWndEdit, (WINBOOL)wParam ); - EnableWindow( lphc->hWndLBox, (WINBOOL)wParam ); - return TRUE; - - case WM_SETREDRAW: - if( wParam ) - lphc->wState &= ~CBF_NOREDRAW; - else - lphc->wState |= CBF_NOREDRAW; - - if( lphc->wState & CBF_EDIT ) - SendMessageA( lphc->hWndEdit, message, wParam, lParam ); - SendMessageA( lphc->hWndLBox, message, wParam, lParam ); - return 0; - - case WM_SYSKEYDOWN: - if( KEYDATA_ALT & HIWORD(lParam) ) - if( wParam == VK_UP || wParam == VK_DOWN ) - COMBO_FlipListbox( lphc, TRUE ); - break; - - case WM_CHAR: - case WM_KEYDOWN: - if( lphc->wState & CBF_EDIT ) - return SendMessageA( lphc->hWndEdit, message, wParam, lParam ); - else - return SendMessageA( lphc->hWndLBox, message, wParam, lParam ); - - case WM_LBUTTONDOWN: - if( !(lphc->wState & CBF_FOCUSED) ) SetFocus( lphc->self->hwndSelf ); - if( lphc->wState & CBF_FOCUSED ) COMBO_LButtonDown( lphc, lParam ); - return TRUE; - - case WM_LBUTTONUP: - COMBO_LButtonUp( lphc, lParam ); - return TRUE; - - case WM_MOUSEMOVE: - if( lphc->wState & CBF_CAPTURE ) - COMBO_MouseMove( lphc, wParam, lParam ); - return TRUE; - - /* Combo messages */ - - case CB_ADDSTRING: - return SendMessageA( lphc->hWndLBox, LB_ADDSTRING, 0, lParam); - - case CB_INSERTSTRING: - return SendMessageA( lphc->hWndLBox, LB_INSERTSTRING, wParam, lParam); - - case CB_DELETESTRING: - return SendMessageA( lphc->hWndLBox, LB_DELETESTRING, wParam, 0); - - case CB_SELECTSTRING: - return COMBO_SelectString( lphc, (INT)wParam, (LPSTR)lParam ); - - case CB_FINDSTRING: - return SendMessageA( lphc->hWndLBox, LB_FINDSTRING, wParam, lParam); - - case CB_FINDSTRINGEXACT: - return SendMessageA( lphc->hWndLBox, LB_FINDSTRINGEXACT, - wParam, lParam ); - - case CB_SETITEMHEIGHT: - return COMBO_SetItemHeight( lphc, (INT)wParam, (INT)lParam); - - case CB_GETITEMHEIGHT: - if( (INT)wParam >= 0 ) /* listbox item */ - return SendMessageA( lphc->hWndLBox, LB_GETITEMHEIGHT, wParam, 0); - return (lphc->RectEdit.bottom - lphc->RectEdit.top); - - case CB_RESETCONTENT: - SendMessageA( lphc->hWndLBox, LB_RESETCONTENT, 0, 0 ); - CBPaintText( lphc, 0 ); - return TRUE; - - case CB_INITSTORAGE: - return SendMessageA( lphc->hWndLBox, LB_INITSTORAGE, wParam, lParam); - - case CB_GETHORIZONTALEXTENT: - return SendMessageA( lphc->hWndLBox, LB_GETHORIZONTALEXTENT, 0, 0); - - case CB_SETHORIZONTALEXTENT: - return SendMessageA( lphc->hWndLBox, LB_SETHORIZONTALEXTENT, wParam, 0); - - case CB_GETTOPINDEX: - return SendMessageA( lphc->hWndLBox, LB_GETTOPINDEX, 0, 0); - - case CB_GETLOCALE: - return SendMessageA( lphc->hWndLBox, LB_GETLOCALE, 0, 0); - - case CB_SETLOCALE: - return SendMessageA( lphc->hWndLBox, LB_SETLOCALE, wParam, 0); - - case CB_GETDROPPEDWIDTH: - if( lphc->droppedWidth ) - return lphc->droppedWidth; - return lphc->RectCombo.right - lphc->RectCombo.left - - (lphc->wState & CBF_EDIT) ? CBitOffset : 0; - - case CB_SETDROPPEDWIDTH: - if( (CB_GETTYPE(lphc) != CBS_SIMPLE) && - (INT)wParam < 768 ) lphc->droppedWidth = (INT)wParam; - return CB_ERR; - - case CB_GETDROPPEDCONTROLRECT: - if( lParam ) CBGetDroppedControlRect(lphc, (LPRECT)lParam ); - return CB_OKAY; - - case CB_GETDROPPEDSTATE: - return (lphc->wState & CBF_DROPPED) ? TRUE : FALSE; - - - case CB_DIR: - return COMBO_Directory( lphc, (UINT)wParam, - (LPSTR)lParam, (message == CB_DIR)); - case CB_SHOWDROPDOWN: - if( CB_GETTYPE(lphc) != CBS_SIMPLE ) - { - if( wParam ) - { - if( !(lphc->wState & CBF_DROPPED) ) - CBDropDown( lphc ); - } - else - if( lphc->wState & CBF_DROPPED ) - CBRollUp( lphc, FALSE, TRUE ); - } - return TRUE; - - case CB_GETCOUNT: - return SendMessageA( lphc->hWndLBox, LB_GETCOUNT, 0, 0); - - case CB_GETCURSEL: - return SendMessageA( lphc->hWndLBox, LB_GETCURSEL, 0, 0); - - case CB_SETCURSEL: - lParam = SendMessageA( lphc->hWndLBox, LB_SETCURSEL, wParam, 0); - if( lphc->wState & CBF_SELCHANGE ) - { - /* no LBN_SELCHANGE in this case, update manually */ - - CBPaintText( lphc, 0 ); - lphc->wState &= ~CBF_SELCHANGE; - } - return lParam; - - - case CB_GETLBTEXT: - return SendMessageA( lphc->hWndLBox, LB_GETTEXT, wParam, lParam); - - case CB_GETLBTEXTLEN: - return SendMessageA( lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0); - - case CB_GETITEMDATA: - return SendMessageA( lphc->hWndLBox, LB_GETITEMDATA, wParam, 0); - - case CB_SETITEMDATA: - return SendMessageA( lphc->hWndLBox, LB_SETITEMDATA, wParam, lParam); - - case CB_GETEDITSEL: - if( lphc->wState & CBF_EDIT ) - { - INT a, b; - - return SendMessageA( lphc->hWndEdit, EM_GETSEL, - (wParam) ? wParam : (WPARAM)&a, - (lParam) ? lParam : (LPARAM)&b ); - } - return CB_ERR; - - - case CB_SETEDITSEL: - if( lphc->wState & CBF_EDIT ) - return SendMessageA( lphc->hWndEdit, EM_SETSEL, - (INT)(INT)LOWORD(lParam), (INT)(INT)HIWORD(lParam) ); - return CB_ERR; - - - case CB_SETEXTENDEDUI: - if( CB_GETTYPE(lphc) == CBS_SIMPLE ) return CB_ERR; - - if( wParam ) - lphc->wState |= CBF_EUI; - else lphc->wState &= ~CBF_EUI; - return CB_OKAY; - - - case CB_GETEXTENDEDUI: - return (lphc->wState & CBF_EUI) ? TRUE : FALSE; - - case (WM_USER + 0x1B): - DPRINT( "[%04x]: undocumented msg!\n", hwnd ); - } - return DefWindowProcA(hwnd, message, wParam, lParam); - } - return CB_ERR; -} - diff --git a/reactos/lib/user32/controls/edit.c b/reactos/lib/user32/controls/edit.c deleted file mode 100644 index 8c41e71a61c..00000000000 --- a/reactos/lib/user32/controls/edit.c +++ /dev/null @@ -1,3803 +0,0 @@ -/* - * Edit control - * - * Copyright David W. Metcalfe, 1994 - * Copyright William Magro, 1995, 1996 - * Copyright Frans van Dorsselaer, 1996, 1997 - * - */ - -/* - * please read EDIT.TODO (and update it when you change things) - */ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0') - FIXME: BTW, new specs say 65535 (do you dare ???) */ -#define BUFLIMIT_SINGLE 766 /* maximum buffer size (not including '\0') */ -#define BUFSTART_MULTI 1024 /* starting size */ -#define BUFSTART_SINGLE 256 /* starting size */ -#define GROWLENGTH 64 /* buffers grow by this much */ -#define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */ - -/* - * extra flags for EDITSTATE.flags field - */ -#define EF_MODIFIED 0x0001 /* text has been modified */ -#define EF_FOCUSED 0x0002 /* we have input focus */ -#define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */ -#define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */ -#define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */ -#define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */ -#define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */ -#define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a - wrapped line, instead of in front of the next character */ -#define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */ - -typedef enum -{ - END_0 = 0, /* line ends with terminating '\0' character */ - END_WRAP, /* line is wrapped */ - END_HARD, /* line ends with a hard return '\r\n' */ - END_SOFT /* line ends with a soft return '\r\r\n' */ -} LINE_END; - -typedef struct tagLINEDEF { - INT length; /* bruto length of a line in bytes */ - INT net_length; /* netto length of a line in visible characters */ - LINE_END ending; - INT width; /* width of the line in pixels */ - struct tagLINEDEF *next; -} LINEDEF; - -typedef INT (CALLBACK *EDITWORDBREAKPROCA)(LPSTR,INT,INT,INT); -typedef INT (CALLBACK *EDITWORDBREAKPROCW)(LPWSTR,INT,INT,INT); - -typedef struct -{ - HANDLE heap; /* our own heap */ - LPSTR text; /* the actual contents of the control */ - INT buffer_size; /* the size of the buffer */ - INT buffer_limit; /* the maximum size to which the buffer may grow */ - HFONT font; /* NULL means standard system font */ - INT x_offset; /* scroll offset for multi lines this is in pixels - for single lines it's in characters */ - INT line_height; /* height of a screen line in pixels */ - INT char_width; /* average character width in pixels */ - DWORD style; /* sane version of wnd->dwStyle */ - WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */ - INT undo_insert_count; /* number of characters inserted in sequence */ - INT undo_position; /* character index of the insertion and deletion */ - LPSTR undo_text; /* deleted text */ - INT undo_buffer_size; /* size of the deleted text buffer */ - INT selection_start; /* == selection_end if no selection */ - INT selection_end; /* == current caret position */ - CHAR password_char; /* == 0 if no password char, and for multi line controls */ - INT left_margin; /* in pixels */ - INT right_margin; /* in pixels */ - RECT format_rect; - INT region_posx; /* Position of cursor relative to region: */ - INT region_posy; /* -1: to left, 0: within, 1: to right */ - EDITWORDBREAKPROCA word_break_procA; - EDITWORDBREAKPROCW word_break_procW; - INT line_count; /* number of lines */ - INT y_offset; /* scroll offset in number of lines */ - /* - * only for multi line controls - */ - INT lock_count; /* amount of re-entries in the EditWndProc */ - INT tabs_count; - LPINT tabs; - INT text_width; /* width of the widest line in pixels */ - LINEDEF *first_line_def; /* linked list of (soft) linebreaks */ - HLOCAL hloc; /* for controls receiving EM_GETHANDLE */ -} EDITSTATE; - -#define SLOWORD(l) ((INT)(LONG)(l)) -#define SHIWORD(l) ((INT)((LONG)(l) >> 16)) - - -#define SWAP_INT(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0) -#define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT((x),(y)); } while(0) - -#define SWAP_UINT(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0) -#define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT((x),(y)); } while(0) - -#define DPRINTF_EDIT_NOTIFY(hwnd, str) \ - ({DPRINT( "notification " str " sent to hwnd=%08x\n", \ - (UINT)(hwnd));}) - -#define EDIT_SEND_CTLCOLOR(wnd,hdc) \ - (SendMessageA((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \ - (WPARAM)(hdc), (LPARAM)(wnd)->hwndSelf)) -#define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \ - (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \ - SendMessageA((wnd)->parent->hwndSelf, WM_COMMAND, \ - MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \ - (LPARAM)(wnd)->hwndSelf)) - -#define DPRINTF_EDIT_MSG(str) \ - DPRINT( \ - " bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \ - (UINT)hwnd, (UINT)wParam, (UINT)lParam) - -/********************************************************************* - * - * Declarations - * - */ - -/* - * These functions have trivial implementations - * We still like to call them internally - * "static __inline__" makes them more like macro's - */ -static __inline__ BOOL EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es); -static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es); -static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es); -static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es); -/* - * This is the only exported function - */ -LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam ); -/* - * Helper functions only valid for one type of control - */ -static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es); -static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es); -static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL extend); -/* - * Helper functions valid for both single line _and_ multi line controls - */ -static INT EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT start, INT index, INT count, INT action); -static INT EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap); -static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y); -static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc); -static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end); -static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es); -static BOOL EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT size); -static BOOL EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT size); -static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL extend); -static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC hdc, INT line, BOOL rev); -static INT EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev); -static void EDIT_SetCaretPos(WND *wnd, EDITSTATE *es, INT pos, BOOL after_wrap); -static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT lprc); -static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL force); -static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action); -/* - * EM_XXX message handlers - */ -static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y); -static BOOL EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL add_eol); -static HLOCAL EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es); -static INT EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT line, LPSTR lpch); -static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, UINT *start, UINT *end); -static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es); -static INT EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT index); -static INT EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT line); -static INT EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT index); -static BOOL EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT dx, INT dy); -static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT index, BOOL after_wrap); -static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace); -static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT action); -static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es); -static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL hloc); -static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT limit); -static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT action, INT left, INT right); -static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c); -static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap); -static BOOL EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT count, LPINT tabs); -static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp); -static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es); -/* - * WM_XXX message handlers - */ -static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data); -static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT code, INT id, HWND conrtol); -static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND hwnd, INT x, INT y); -static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es); -static LRESULT EDIT_WM_Create(WND *wnd, EDITSTATE *es, LPCREATESTRUCT cs); -static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es); -static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC dc); -static INT EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT count, LPSTR text); -static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar); -static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data); -static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND window_getting_focus); -static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y); -static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y); -static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y); -static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y); -static LRESULT EDIT_WM_NCCreate(WND *wnd, LPCREATESTRUCT cs); -static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es); -static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es); -static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND window_losing_focus); -static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT font, BOOL redraw); -static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text); -static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT action, INT width, INT height); -static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data); -static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT id, TIMERPROC timer_proc); -static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar); - - -/********************************************************************* - * - * EM_CANUNDO - * - */ -static __inline__ BOOL EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es) -{ - return (es->undo_insert_count || lstrlenA(es->undo_text)); -} - - -/********************************************************************* - * - * EM_EMPTYUNDOBUFFER - * - */ -static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es) -{ - es->undo_insert_count = 0; - *es->undo_text = '\0'; -} - - -/********************************************************************* - * - * WM_CLEAR - * - */ -static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es) -{ - EDIT_EM_ReplaceSel(wnd, es, TRUE, ""); -} - - -/********************************************************************* - * - * WM_CUT - * - */ -static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es) -{ - EDIT_WM_Copy(wnd, es); - EDIT_WM_Clear(wnd, es); -} - - -/********************************************************************* - * - * EditWndProc() - * - * The messages are in the order of the actual integer values - * (which can be found in include/windows.h) - * Whereever possible the 16 bit versions are converted to - * the bit ones, so that we can 'fall through' to the - * helper functions. These are mostly bit (with a few - * exceptions, clearly indicated by a '16' extension to their - * names). - * - */ -LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam ) -{ - WND *wnd = WIN_FindWndPtr(hwnd); - EDITSTATE *es = *(EDITSTATE **)((wnd)->wExtra); - LRESULT result = 0; - - switch (msg) { - case WM_DESTROY: - DPRINTF_EDIT_MSG("WM_DESTROY"); - EDIT_WM_Destroy(wnd, es); - return 0; - - case WM_NCCREATE: - DPRINTF_EDIT_MSG("WM_NCCREATE"); - return EDIT_WM_NCCreate(wnd, (LPCREATESTRUCT)lParam); - } - - if (!es) - return DefWindowProcA(hwnd, msg, wParam, lParam); - - EDIT_LockBuffer(wnd, es); - switch (msg) { - case EM_GETSEL: - DPRINTF_EDIT_MSG("EM_GETSEL"); - result = EDIT_EM_GetSel(wnd, es, (UINT *)wParam, (UINT *)lParam); - break; - - - case EM_SETSEL: - DPRINTF_EDIT_MSG("EM_SETSEL"); - EDIT_EM_SetSel(wnd, es, wParam, lParam, FALSE); - result = 1; - break; - - - case EM_GETRECT: - DPRINTF_EDIT_MSG("EM_GETRECT"); - if (lParam) - CopyRect((LPRECT)lParam, &es->format_rect); - break; - - - case EM_SETRECT: - DPRINTF_EDIT_MSG("EM_SETRECT"); - if ((es->style & ES_MULTILINE) && lParam) { - EDIT_SetRectNP(wnd, es, (LPRECT)lParam); - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - } - break; - - - case EM_SETRECTNP: - DPRINTF_EDIT_MSG("EM_SETRECTNP"); - if ((es->style & ES_MULTILINE) && lParam) - EDIT_SetRectNP(wnd, es, (LPRECT)lParam); - break; - - - case EM_SCROLL: - DPRINTF_EDIT_MSG("EM_SCROLL"); - result = EDIT_EM_Scroll(wnd, es, (INT)wParam); - break; - - - case EM_LINESCROLL: - DPRINTF_EDIT_MSG("EM_LINESCROLL"); - result = (LRESULT)EDIT_EM_LineScroll(wnd, es, (INT)wParam, (INT)lParam); - break; - - - case EM_SCROLLCARET: - DPRINTF_EDIT_MSG("EM_SCROLLCARET"); - EDIT_EM_ScrollCaret(wnd, es); - result = 1; - break; - - case EM_GETMODIFY: - DPRINTF_EDIT_MSG("EM_GETMODIFY"); - return ((es->flags & EF_MODIFIED) != 0); - break; - - case EM_SETMODIFY: - DPRINTF_EDIT_MSG("EM_SETMODIFY"); - if (wParam) - es->flags |= EF_MODIFIED; - else - es->flags &= ~EF_MODIFIED; - break; - - case EM_GETLINECOUNT: - DPRINTF_EDIT_MSG("EM_GETLINECOUNT"); - result = (es->style & ES_MULTILINE) ? es->line_count : 1; - break; - - case EM_LINEINDEX: - DPRINTF_EDIT_MSG("EM_LINEINDEX"); - result = (LRESULT)EDIT_EM_LineIndex(wnd, es, (INT)wParam); - break; - - case EM_SETHANDLE: - DPRINTF_EDIT_MSG("EM_SETHANDLE"); - EDIT_EM_SetHandle(wnd, es, (HLOCAL)wParam); - break; - - case EM_GETHANDLE: - DPRINTF_EDIT_MSG("EM_GETHANDLE"); - result = (LRESULT)EDIT_EM_GetHandle(wnd, es); - break; - - case EM_GETTHUMB: - DPRINTF_EDIT_MSG("EM_GETTHUMB"); - result = EDIT_EM_GetThumb(wnd, es); - break; - - /* messages 0x00bf and 0x00c0 missing from specs */ - - case 0x00bf: - DPRINTF_EDIT_MSG("undocumented 0x00bf, please report"); - result = DefWindowProcA(hwnd, msg, wParam, lParam); - break; - - case 0x00c0: - DPRINTF_EDIT_MSG("undocumented 0x00c0, please report"); - result = DefWindowProcA(hwnd, msg, wParam, lParam); - break; - - case EM_LINELENGTH: - DPRINTF_EDIT_MSG("EM_LINELENGTH"); - result = (LRESULT)EDIT_EM_LineLength(wnd, es, (INT)wParam); - break; - - - case EM_REPLACESEL: - DPRINTF_EDIT_MSG("EM_REPLACESEL"); - EDIT_EM_ReplaceSel(wnd, es, (BOOL)wParam, (LPCSTR)lParam); - result = 1; - break; - - /* message 0x00c3 missing from specs */ - - case 0x00c3: - DPRINTF_EDIT_MSG("undocumented 0x00c3, please report"); - result = DefWindowProcA(hwnd, msg, wParam, lParam); - break; - - case EM_GETLINE: - DPRINTF_EDIT_MSG("EM_GETLINE"); - result = (LRESULT)EDIT_EM_GetLine(wnd, es, (INT)wParam, (LPSTR)lParam); - break; - - case EM_SETLIMITTEXT: - DPRINTF_EDIT_MSG("EM_SETLIMITTEXT"); - EDIT_EM_SetLimitText(wnd, es, (INT)wParam); - break; - - case EM_CANUNDO: - DPRINTF_EDIT_MSG("EM_CANUNDO"); - result = (LRESULT)EDIT_EM_CanUndo(wnd, es); - break; - - case EM_UNDO: - /* fall through */ - case WM_UNDO: - DPRINTF_EDIT_MSG("EM_UNDO / WM_UNDO"); - result = (LRESULT)EDIT_EM_Undo(wnd, es); - break; - - case EM_FMTLINES: - DPRINTF_EDIT_MSG("EM_FMTLINES"); - result = (LRESULT)EDIT_EM_FmtLines(wnd, es, (BOOL)wParam); - break; - - case EM_LINEFROMCHAR: - DPRINTF_EDIT_MSG("EM_LINEFROMCHAR"); - result = (LRESULT)EDIT_EM_LineFromChar(wnd, es, (INT)wParam); - break; - - /* message 0x00ca missing from specs */ - - case 0x00ca: - DPRINTF_EDIT_MSG("undocumented 0x00ca, please report"); - result = DefWindowProcA(hwnd, msg, wParam, lParam); - break; - - case EM_SETTABSTOPS: - DPRINTF_EDIT_MSG("EM_SETTABSTOPS"); - result = (LRESULT)EDIT_EM_SetTabStops(wnd, es, (INT)wParam, (LPINT)lParam); - break; - - case EM_SETPASSWORDCHAR: - DPRINTF_EDIT_MSG("EM_SETPASSWORDCHAR"); - EDIT_EM_SetPasswordChar(wnd, es, (CHAR)wParam); - break; - - case EM_EMPTYUNDOBUFFER: - DPRINTF_EDIT_MSG("EM_EMPTYUNDOBUFFER"); - EDIT_EM_EmptyUndoBuffer(wnd, es); - break; - - case EM_GETFIRSTVISIBLELINE: - DPRINTF_EDIT_MSG("EM_GETFIRSTVISIBLELINE"); - result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset; - break; - - case EM_SETREADONLY: - DPRINTF_EDIT_MSG("EM_SETREADONLY"); - if (wParam) { - wnd->dwStyle |= ES_READONLY; - es->style |= ES_READONLY; - } else { - wnd->dwStyle &= ~ES_READONLY; - es->style &= ~ES_READONLY; - } - return 1; - break; - - case EM_SETWORDBREAKPROC: - DPRINTF_EDIT_MSG("EM_SETWORDBREAKPROC"); - EDIT_EM_SetWordBreakProc(wnd, es, (EDITWORDBREAKPROCA)lParam); - break; - - case EM_GETWORDBREAKPROC: - DPRINTF_EDIT_MSG("EM_GETWORDBREAKPROC"); - result = (LRESULT)es->word_break_procA; - break; - - case EM_GETPASSWORDCHAR: - DPRINTF_EDIT_MSG("EM_GETPASSWORDCHAR"); - result = es->password_char; - break; - - /* The following EM_xxx are new to win95 and don't exist for 16 bit */ - - case EM_SETMARGINS: - DPRINTF_EDIT_MSG("EM_SETMARGINS"); - EDIT_EM_SetMargins(wnd, es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case EM_GETMARGINS: - DPRINTF_EDIT_MSG("EM_GETMARGINS"); - result = MAKELONG(es->left_margin, es->right_margin); - break; - - case EM_GETLIMITTEXT: - DPRINTF_EDIT_MSG("EM_GETLIMITTEXT"); - result = es->buffer_limit; - break; - - case EM_POSFROMCHAR: - DPRINTF_EDIT_MSG("EM_POSFROMCHAR"); - result = EDIT_EM_PosFromChar(wnd, es, (INT)wParam, FALSE); - break; - - case EM_CHARFROMPOS: - DPRINTF_EDIT_MSG("EM_CHARFROMPOS"); - result = EDIT_EM_CharFromPos(wnd, es, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case WM_GETDLGCODE: - DPRINTF_EDIT_MSG("WM_GETDLGCODE"); - result = (es->style & ES_MULTILINE) ? - DLGC_WANTALLKEYS | DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS : - DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS; - break; - - case WM_CHAR: - DPRINTF_EDIT_MSG("WM_CHAR"); - EDIT_WM_Char(wnd, es, (CHAR)wParam, (DWORD)lParam); - break; - - case WM_CLEAR: - DPRINTF_EDIT_MSG("WM_CLEAR"); - EDIT_WM_Clear(wnd, es); - break; - - case WM_COMMAND: - DPRINTF_EDIT_MSG("WM_COMMAND"); - EDIT_WM_Command(wnd, es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam); - break; - - case WM_CONTEXTMENU: - DPRINTF_EDIT_MSG("WM_CONTEXTMENU"); - EDIT_WM_ContextMenu(wnd, es, (HWND)wParam, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case WM_COPY: - DPRINTF_EDIT_MSG("WM_COPY"); - EDIT_WM_Copy(wnd, es); - break; - - case WM_CREATE: - DPRINTF_EDIT_MSG("WM_CREATE"); - result = EDIT_WM_Create(wnd, es, (LPCREATESTRUCT)lParam); - break; - - case WM_CUT: - DPRINTF_EDIT_MSG("WM_CUT"); - EDIT_WM_Cut(wnd, es); - break; - - case WM_ENABLE: - DPRINTF_EDIT_MSG("WM_ENABLE"); - InvalidateRect(hwnd, NULL, TRUE); - break; - - case WM_ERASEBKGND: - DPRINTF_EDIT_MSG("WM_ERASEBKGND"); - result = EDIT_WM_EraseBkGnd(wnd, es, (HDC)wParam); - break; - - case WM_GETFONT: - DPRINTF_EDIT_MSG("WM_GETFONT"); - result = (LRESULT)es->font; - break; - - case WM_GETTEXT: - DPRINTF_EDIT_MSG("WM_GETTEXT"); - result = (LRESULT)EDIT_WM_GetText(wnd, es, (INT)wParam, (LPSTR)lParam); - break; - - case WM_GETTEXTLENGTH: - DPRINTF_EDIT_MSG("WM_GETTEXTLENGTH"); - result = lstrlenA(es->text); - break; - - case WM_HSCROLL: - DPRINTF_EDIT_MSG("WM_HSCROLL"); - result = EDIT_WM_HScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)lParam); - break; - - case WM_KEYDOWN: - DPRINTF_EDIT_MSG("WM_KEYDOWN"); - result = EDIT_WM_KeyDown(wnd, es, (INT)wParam, (DWORD)lParam); - break; - - case WM_KILLFOCUS: - DPRINTF_EDIT_MSG("WM_KILLFOCUS"); - result = EDIT_WM_KillFocus(wnd, es, (HWND)wParam); - break; - - case WM_LBUTTONDBLCLK: - DPRINTF_EDIT_MSG("WM_LBUTTONDBLCLK"); - result = EDIT_WM_LButtonDblClk(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case WM_LBUTTONDOWN: - DPRINTF_EDIT_MSG("WM_LBUTTONDOWN"); - result = EDIT_WM_LButtonDown(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case WM_LBUTTONUP: - DPRINTF_EDIT_MSG("WM_LBUTTONUP"); - result = EDIT_WM_LButtonUp(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case WM_MOUSEACTIVATE: - /* - * FIXME: maybe DefWindowProc() screws up, but it seems that - * modalless dialog boxes need this. If we don't do this, the focus - * will _not_ be set by DefWindowProc() for edit controls in a - * modalless dialog box ??? - */ - DPRINTF_EDIT_MSG("WM_MOUSEACTIVATE"); - SetFocus(wnd->hwndSelf); - result = MA_ACTIVATE; - break; - - case WM_MOUSEMOVE: - /* - * DPRINTF_EDIT_MSG("WM_MOUSEMOVE"); - */ - result = EDIT_WM_MouseMove(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); - break; - - case WM_PAINT: - DPRINTF_EDIT_MSG("WM_PAINT"); - EDIT_WM_Paint(wnd, es); - break; - - case WM_PASTE: - DPRINTF_EDIT_MSG("WM_PASTE"); - EDIT_WM_Paste(wnd, es); - break; - - case WM_SETFOCUS: - DPRINTF_EDIT_MSG("WM_SETFOCUS"); - EDIT_WM_SetFocus(wnd, es, (HWND)wParam); - break; - - case WM_SETFONT: - DPRINTF_EDIT_MSG("WM_SETFONT"); - EDIT_WM_SetFont(wnd, es, (HFONT)wParam, LOWORD(lParam) != 0); - break; - - case WM_SETTEXT: - DPRINTF_EDIT_MSG("WM_SETTEXT"); - EDIT_WM_SetText(wnd, es, (LPCSTR)lParam); - result = TRUE; - break; - - case WM_SIZE: - DPRINTF_EDIT_MSG("WM_SIZE"); - EDIT_WM_Size(wnd, es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam)); - break; - - case WM_SYSKEYDOWN: - DPRINTF_EDIT_MSG("WM_SYSKEYDOWN"); - result = EDIT_WM_SysKeyDown(wnd, es, (INT)wParam, (DWORD)lParam); - break; - - case WM_TIMER: - DPRINTF_EDIT_MSG("WM_TIMER"); - EDIT_WM_Timer(wnd, es, (INT)wParam, (TIMERPROC)lParam); - break; - - case WM_VSCROLL: - DPRINTF_EDIT_MSG("WM_VSCROLL"); - result = EDIT_WM_VScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)(lParam)); - break; - - default: - result = DefWindowProcA(hwnd, msg, wParam, lParam); - break; - } - EDIT_UnlockBuffer(wnd, es, FALSE); - return result; -} - - -/********************************************************************* - * - * EDIT_BuildLineDefs_ML - * - * Build linked list of text lines. - * Lines can end with '\0' (last line), a character (if it is wrapped), - * a soft return '\r\r\n' or a hard return '\r\n' - * - */ -static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es) -{ - HDC dc; - HFONT old_font = 0; - LPSTR start, cp; - INT fw; - LINEDEF *current_def; - LINEDEF **previous_next; - - current_def = es->first_line_def; - do { - LINEDEF *next_def = current_def->next; - HeapFree(es->heap, 0, current_def); - current_def = next_def; - } while (current_def); - es->line_count = 0; - es->text_width = 0; - - dc = GetDC(wnd->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - - fw = es->format_rect.right - es->format_rect.left; - start = es->text; - previous_next = &es->first_line_def; - do { - current_def = HeapAlloc(es->heap, 0, sizeof(LINEDEF)); - current_def->next = NULL; - cp = start; - while (*cp) { - if ((*cp == '\r') && (*(cp + 1) == '\n')) - break; - cp++; - } - if (!(*cp)) { - current_def->ending = END_0; - current_def->net_length = lstrlenA(start); - } else if ((cp > start) && (*(cp - 1) == '\r')) { - current_def->ending = END_SOFT; - current_def->net_length = cp - start - 1; - } else { - current_def->ending = END_HARD; - current_def->net_length = cp - start; - } - current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, - start, current_def->net_length, - es->tabs_count, es->tabs)); - /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 767 ???) */ - if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) { - INT next = 0; - INT prev; - do { - prev = next; - next = EDIT_CallWordBreakProc(wnd, es, start - es->text, - prev + 1, current_def->net_length, WB_RIGHT); - current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, - start, next, es->tabs_count, es->tabs)); - } while (current_def->width <= fw); - if (!prev) { - next = 0; - do { - prev = next; - next++; - current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, - start, next, es->tabs_count, es->tabs)); - } while (current_def->width <= fw); - if (!prev) - prev = 1; - } - current_def->net_length = prev; - current_def->ending = END_WRAP; - current_def->width = (INT)LOWORD(GetTabbedTextExtentA(dc, start, - current_def->net_length, es->tabs_count, es->tabs)); - } - switch (current_def->ending) { - case END_SOFT: - current_def->length = current_def->net_length + 3; - break; - case END_HARD: - current_def->length = current_def->net_length + 2; - break; - case END_WRAP: - case END_0: - current_def->length = current_def->net_length; - break; - } - es->text_width = max(es->text_width, current_def->width); - start += current_def->length; - *previous_next = current_def; - previous_next = ¤t_def->next; - es->line_count++; - } while (current_def->ending != END_0); - if (es->font) - SelectObject(dc, old_font); - ReleaseDC(wnd->hwndSelf, dc); -} - - -/********************************************************************* - * - * EDIT_CallWordBreakProc - * - * Call appropriate WordBreakProc (internal or external). - * - * Note: The "start" argument should always be an index refering - * to es->text. The actual wordbreak proc might be - * 16 bit, so we can't always pass any bit LPSTR. - * Hence we assume that es->text is the buffer that holds - * the string under examination (we can decide this for ourselves). - * - */ -static INT EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT start, INT index, INT count, INT action) -{ - if (es->word_break_procA) - { - DPRINT("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n", - es->word_break_procA, es->text + start, index, - count, action ); - return (INT)es->word_break_procA( es->text + start, index, - count, action ); - } - else - return EDIT_WordBreakProc(es->text + start, index, count, action); -} - - -/********************************************************************* - * - * EDIT_CharFromPos - * - * Beware: This is not the function called on EM_CHARFROMPOS - * The position _can_ be outside the formatting / client - * rectangle - * The return value is only the character index - * - */ -static INT EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap) -{ - INT index; - HDC dc; - HFONT old_font = 0; - - if (es->style & ES_MULTILINE) { - INT line = (y - es->format_rect.top) / es->line_height + es->y_offset; - INT line_index = 0; - LINEDEF *line_def = es->first_line_def; - INT low, high; - while ((line > 0) && line_def->next) { - line_index += line_def->length; - line_def = line_def->next; - line--; - } - x += es->x_offset - es->format_rect.left; - if (x >= line_def->width) { - if (after_wrap) - *after_wrap = (line_def->ending == END_WRAP); - return line_index + line_def->net_length; - } - if (x <= 0) { - if (after_wrap) - *after_wrap = FALSE; - return line_index; - } - dc = GetDC(wnd->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - low = line_index + 1; - high = line_index + line_def->net_length + 1; - while (low < high - 1) - { - INT mid = (low + high) / 2; - if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid; - else low = mid; - } - index = low; - - if (after_wrap) - *after_wrap = ((index == line_index + line_def->net_length) && - (line_def->ending == END_WRAP)); - } else { - LPSTR text; - SIZE size; - if (after_wrap) - *after_wrap = FALSE; - x -= es->format_rect.left; - if (!x) - return es->x_offset; - text = EDIT_GetPasswordPointer_SL(wnd, es); - dc = GetDC(wnd->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - if (x < 0) - { - INT low = 0; - INT high = es->x_offset; - while (low < high - 1) - { - INT mid = (low + high) / 2; - GetTextExtentPointA( dc, text + mid, - es->x_offset - mid, &size ); - if (size.cx > -x) low = mid; - else high = mid; - } - index = low; - } - else - { - INT low = es->x_offset; - INT high = lstrlenA(es->text) + 1; - while (low < high - 1) - { - INT mid = (low + high) / 2; - GetTextExtentPointA( dc, text + es->x_offset, - mid - es->x_offset, &size ); - if (size.cx > x) high = mid; - else low = mid; - } - index = low; - } - if (es->style & ES_PASSWORD) - HeapFree(es->heap, 0 ,text); - } - if (es->font) - SelectObject(dc, old_font); - ReleaseDC(wnd->hwndSelf, dc); - return index; -} - - -/********************************************************************* - * - * EDIT_ConfinePoint - * - * adjusts the point to be within the formatting rectangle - * (so CharFromPos returns the nearest _visible_ character) - * - */ -static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT x, LPINT y) -{ - *x = min(max(*x, es->format_rect.left), es->format_rect.right - 1); - *y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1); -} - - -/********************************************************************* - * - * EDIT_GetLineRect - * - * Calculates the bounding rectangle for a line from a starting - * column to an ending column. - * - */ -static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc) -{ - INT line_index = EDIT_EM_LineIndex(wnd, es, line); - - if (es->style & ES_MULTILINE) - rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height; - else - rc->top = es->format_rect.top; - rc->bottom = rc->top + es->line_height; - rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE)); - rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + ecol, TRUE)); -} - - -/********************************************************************* - * - * EDIT_GetPasswordPointer_SL - * - * note: caller should free the (optionally) allocated buffer - * - */ -static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es) -{ - if (es->style & ES_PASSWORD) { - INT len = lstrlenA(es->text); - LPSTR text = HeapAlloc(es->heap, 0, len + 1); - HEAP_memset(text, len, es->password_char); - text[len] = '\0'; - return text; - } else - return es->text; -} - - -/********************************************************************* - * - * EDIT_LockBuffer - * - * This acts as a LOCAL_Lock(), but it locks only once. This way - * you can call it whenever you like, without unlocking. - * - */ -static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es) -{ - if (!es) { - DPRINT( "no EDITSTATE ... please report\n"); - return; - } - if (!(es->style & ES_MULTILINE)) - return; - if (!es->text) { - if (es->hloc) - es->text = LocalLock(es->hloc); - else { - DPRINT( "no buffer ... please report\n"); - return; - } - } - es->lock_count++; -} - - -/********************************************************************* - * - * EDIT_SL_InvalidateText - * - * Called from EDIT_InvalidateText(). - * Does the job for single-line controls only. - * - */ -static void EDIT_SL_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end) -{ - RECT line_rect; - RECT rc; - - EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect); - if (IntersectRect(&rc, &line_rect, &es->format_rect)) - InvalidateRect(wnd->hwndSelf, &rc, FALSE); -} - - -/********************************************************************* - * - * EDIT_ML_InvalidateText - * - * Called from EDIT_InvalidateText(). - * Does the job for multi-line controls only. - * - */ -static void EDIT_ML_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end) -{ - INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; - INT sl = EDIT_EM_LineFromChar(wnd, es, start); - INT el = EDIT_EM_LineFromChar(wnd, es, end); - INT sc; - INT ec; - RECT rc1; - RECT rcWnd; - RECT rcLine; - RECT rcUpdate; - INT l; - - if ((el < es->y_offset) || (sl > es->y_offset + vlc)) - return; - - sc = start - EDIT_EM_LineIndex(wnd, es, sl); - ec = end - EDIT_EM_LineIndex(wnd, es, el); - if (sl < es->y_offset) { - sl = es->y_offset; - sc = 0; - } - if (el > es->y_offset + vlc) { - el = es->y_offset + vlc; - ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el)); - } - GetClientRect(wnd->hwndSelf, &rc1); - IntersectRect(&rcWnd, &rc1, &es->format_rect); - if (sl == el) { - EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine); - if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) - InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE); - } else { - EDIT_GetLineRect(wnd, es, sl, sc, - EDIT_EM_LineLength(wnd, es, - EDIT_EM_LineIndex(wnd, es, sl)), - &rcLine); - if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) - InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE); - for (l = sl + 1 ; l < el ; l++) { - EDIT_GetLineRect(wnd, es, l, 0, - EDIT_EM_LineLength(wnd, es, - EDIT_EM_LineIndex(wnd, es, l)), - &rcLine); - if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) - InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE); - } - EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine); - if (IntersectRect(&rcUpdate, &rcWnd, &rcLine)) - InvalidateRect(wnd->hwndSelf, &rcUpdate, FALSE); - } -} - - -/********************************************************************* - * - * EDIT_InvalidateText - * - * Invalidate the text from offset start upto, but not including, - * offset end. Useful for (re)painting the selection. - * Regions outside the linewidth are not invalidated. - * end == -1 means end == TextLength. - * start and end need not be ordered. - * - */ -static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT start, INT end) -{ - if (end == start) - return; - - if (end == -1) - end = lstrlenA(es->text); - - ORDER_INT(start, end); - - if (es->style & ES_MULTILINE) - EDIT_ML_InvalidateText(wnd, es, start, end); - else - EDIT_SL_InvalidateText(wnd, es, start, end); -} - - -/********************************************************************* - * - * EDIT_MakeFit - * - * Try to fit size + 1 bytes in the buffer. Constrain to limits. - * - */ -static BOOL EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT size) -{ - HLOCAL hNew; - - if (size <= es->buffer_size) - return TRUE; - if (size > es->buffer_limit) { - EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT"); - return FALSE; - } - size = ((size / GROWLENGTH) + 1) * GROWLENGTH; - if (size > es->buffer_limit) - size = es->buffer_limit; - - DPRINT( "trying to ReAlloc to %d+1\n", size); - - EDIT_UnlockBuffer(wnd, es, TRUE); - if (es->text) { - if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1))) - es->buffer_size = min(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit); - else - es->buffer_size = 0; - } else if (es->hloc) { - if ((hNew = LocalReAlloc(es->hloc, size + 1, 0))) { - DPRINT( "Old bit handle %08x, new handle %08x\n", es->hloc, hNew); - es->hloc = hNew; - es->buffer_size = min(LocalSize(es->hloc) - 1, es->buffer_limit); - } - } - if (es->buffer_size < size) { - EDIT_LockBuffer(wnd, es); - DPRINT( "FAILED ! We now have %d+1\n", es->buffer_size); - EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE"); - return FALSE; - } else { - EDIT_LockBuffer(wnd, es); - DPRINT( "We now have %d+1\n", es->buffer_size); - return TRUE; - } -} - - -/********************************************************************* - * - * EDIT_MakeUndoFit - * - * Try to fit size + 1 bytes in the undo buffer. - * - */ -static BOOL EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT size) -{ - if (size <= es->undo_buffer_size) - return TRUE; - size = ((size / GROWLENGTH) + 1) * GROWLENGTH; - - DPRINT( "trying to ReAlloc to %d+1\n", size); - - if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) { - es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; - if (es->undo_buffer_size < size) { - DPRINT( "FAILED ! We now have %d+1\n", es->undo_buffer_size); - return FALSE; - } - return TRUE; - } - return FALSE; -} - - -/********************************************************************* - * - * EDIT_MoveBackward - * - */ -static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT e = es->selection_end; - - if (e) { - e--; - if ((es->style & ES_MULTILINE) && e && - (es->text[e - 1] == '\r') && (es->text[e] == '\n')) { - e--; - if (e && (es->text[e - 1] == '\r')) - e--; - } - } - EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveDown_ML - * - * Only for multi line controls - * Move the caret one line down, on a column with the nearest - * x coordinate on the screen (might be a different column). - * - */ -static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT s = es->selection_start; - INT e = es->selection_end; - BOOL after_wrap = (es->flags & EF_AFTER_WRAP); - LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); - INT x = SLOWORD(pos); - INT y = SHIWORD(pos); - - e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap); - if (!extend) - s = e; - EDIT_EM_SetSel(wnd, es, s, e, after_wrap); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveEnd - * - */ -static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL extend) -{ - BOOL after_wrap = FALSE; - INT e; - - if (es->style & ES_MULTILINE) - e = EDIT_CharFromPos(wnd, es, 0x7fffffff, - HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap); - else - e = lstrlenA(es->text); - EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveForward - * - */ -static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT e = es->selection_end; - - if (es->text[e]) { - e++; - if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) { - if (es->text[e] == '\n') - e++; - else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n')) - e += 2; - } - } - EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveHome - * - * Home key: move to beginning of line. - * - */ -static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT e; - - if (es->style & ES_MULTILINE) - e = EDIT_CharFromPos(wnd, es, 0x80000000, - HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL); - else - e = 0; - EDIT_EM_SetSel(wnd, es, e, extend ? es->selection_start : e, FALSE); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MovePageDown_ML - * - * Only for multi line controls - * Move the caret one page down, on a column with the nearest - * x coordinate on the screen (might be a different column). - * - */ -static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT s = es->selection_start; - INT e = es->selection_end; - BOOL after_wrap = (es->flags & EF_AFTER_WRAP); - LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); - INT x = SLOWORD(pos); - INT y = SHIWORD(pos); - - e = EDIT_CharFromPos(wnd, es, x, - y + (es->format_rect.bottom - es->format_rect.top), - &after_wrap); - if (!extend) - s = e; - EDIT_EM_SetSel(wnd, es, s, e, after_wrap); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MovePageUp_ML - * - * Only for multi line controls - * Move the caret one page up, on a column with the nearest - * x coordinate on the screen (might be a different column). - * - */ -static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT s = es->selection_start; - INT e = es->selection_end; - BOOL after_wrap = (es->flags & EF_AFTER_WRAP); - LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); - INT x = SLOWORD(pos); - INT y = SHIWORD(pos); - - e = EDIT_CharFromPos(wnd, es, x, - y - (es->format_rect.bottom - es->format_rect.top), - &after_wrap); - if (!extend) - s = e; - EDIT_EM_SetSel(wnd, es, s, e, after_wrap); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveUp_ML - * - * Only for multi line controls - * Move the caret one line up, on a column with the nearest - * x coordinate on the screen (might be a different column). - * - */ -static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT s = es->selection_start; - INT e = es->selection_end; - BOOL after_wrap = (es->flags & EF_AFTER_WRAP); - LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); - INT x = SLOWORD(pos); - INT y = SHIWORD(pos); - - e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap); - if (!extend) - s = e; - EDIT_EM_SetSel(wnd, es, s, e, after_wrap); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveWordBackward - * - */ -static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT s = es->selection_start; - INT e = es->selection_end; - INT l; - INT ll; - INT li; - - l = EDIT_EM_LineFromChar(wnd, es, e); - ll = EDIT_EM_LineLength(wnd, es, e); - li = EDIT_EM_LineIndex(wnd, es, l); - if (e - li == 0) { - if (l) { - li = EDIT_EM_LineIndex(wnd, es, l - 1); - e = li + EDIT_EM_LineLength(wnd, es, li); - } - } else { - e = li + (INT)EDIT_CallWordBreakProc(wnd, es, - li, e - li, ll, WB_LEFT); - } - if (!extend) - s = e; - EDIT_EM_SetSel(wnd, es, s, e, FALSE); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_MoveWordForward - * - */ -static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL extend) -{ - INT s = es->selection_start; - INT e = es->selection_end; - INT l; - INT ll; - INT li; - - l = EDIT_EM_LineFromChar(wnd, es, e); - ll = EDIT_EM_LineLength(wnd, es, e); - li = EDIT_EM_LineIndex(wnd, es, l); - if (e - li == ll) { - if ((es->style & ES_MULTILINE) && (l != es->line_count - 1)) - e = EDIT_EM_LineIndex(wnd, es, l + 1); - } else { - e = li + EDIT_CallWordBreakProc(wnd, es, - li, e - li + 1, ll, WB_RIGHT); - } - if (!extend) - s = e; - EDIT_EM_SetSel(wnd, es, s, e, FALSE); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * EDIT_PaintLine - * - */ -static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC dc, INT line, BOOL rev) -{ - INT s = es->selection_start; - INT e = es->selection_end; - INT li; - INT ll; - INT x; - INT y; - LRESULT pos; - - if (es->style & ES_MULTILINE) { - INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; - if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count)) - return; - } else if (line) - return; - - DPRINT( "line=%d\n", line); - - pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE); - x = SLOWORD(pos); - y = SHIWORD(pos); - li = EDIT_EM_LineIndex(wnd, es, line); - ll = EDIT_EM_LineLength(wnd, es, li); - s = es->selection_start; - e = es->selection_end; - ORDER_INT(s, e); - s = min(li + ll, max(li, s)); - e = min(li + ll, max(li, e)); - if (rev && (s != e) && - ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) { - x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE); - x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE); - x += EDIT_PaintText(wnd, es, dc, x, y, line, e - li, li + ll - e, FALSE); - } else - x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE); -} - - -/********************************************************************* - * - * EDIT_PaintText - * - */ -static INT EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev) -{ - COLORREF BkColor; - COLORREF TextColor; - INT ret; - INT li; - SIZE size; - - if (!count) - return 0; - BkColor = GetBkColor(dc); - TextColor = GetTextColor(dc); - if (rev) { - SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT)); - SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - } - li = EDIT_EM_LineIndex(wnd, es, line); - if (es->style & ES_MULTILINE) { - ret = (INT)LOWORD(TabbedTextOutA(dc, x, y, es->text + li + col, count, - es->tabs_count, es->tabs, es->format_rect.left - es->x_offset)); - } else { - LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es); - TextOutA(dc, x, y, text + li + col, count); - GetTextExtentPointA(dc, text + li + col, count, &size); - ret = size.cx; - if (es->style & ES_PASSWORD) - HeapFree(es->heap, 0, text); - } - if (rev) { - SetBkColor(dc, BkColor); - SetTextColor(dc, TextColor); - } - return ret; -} - - -/********************************************************************* - * - * EDIT_SetCaretPos - * - */ -static void EDIT_SetCaretPos(WND *wnd, EDITSTATE *es, INT pos, - BOOL after_wrap) -{ - LRESULT res = EDIT_EM_PosFromChar(wnd, es, pos, after_wrap); - INT x = SLOWORD(res); - INT y = SHIWORD(res); - - if(x < es->format_rect.left) - x = es->format_rect.left; - if(x > es->format_rect.right - 2) - x = es->format_rect.right - 2; - if(y > es->format_rect.bottom) - y = es->format_rect.bottom; - if(y < es->format_rect.top) - y = es->format_rect.top; - SetCaretPos(x, y); - return; -} - - -/********************************************************************* - * - * EDIT_SetRectNP - * - * note: this is not (exactly) the handler called on EM_SETRECTNP - * it is also used to set the rect of a single line control - * - */ -static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT rc) -{ - CopyRect(&es->format_rect, rc); - if (es->style & WS_BORDER) { - INT bw = GetSystemMetrics(SM_CXBORDER) + 1; - if(TWEAK_WineLook == WIN31_LOOK) - bw += 2; - es->format_rect.left += bw; - es->format_rect.top += bw; - es->format_rect.right -= bw; - es->format_rect.bottom -= bw; - } - es->format_rect.left += es->left_margin; - es->format_rect.right -= es->right_margin; - es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width); - if (es->style & ES_MULTILINE) - es->format_rect.bottom = es->format_rect.top + - max(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height; - else - es->format_rect.bottom = es->format_rect.top + es->line_height; - if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) - EDIT_BuildLineDefs_ML(wnd, es); -} - - -/********************************************************************* - * - * EDIT_UnlockBuffer - * - */ -static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL force) -{ - if (!es) { - DPRINT( "no EDITSTATE ... please report\n"); - return; - } - if (!(es->style & ES_MULTILINE)) - return; - if (!es->lock_count) { - DPRINT( "lock_count == 0 ... please report\n"); - return; - } - if (!es->text) { - DPRINT( "es->text == 0 ... please report\n"); - return; - } - if (force || (es->lock_count == 1)) { - if (es->hloc) { - LocalUnlock(es->hloc); - es->text = NULL; - } - } - es->lock_count--; -} - - -/********************************************************************* - * - * EDIT_WordBreakProc - * - * Find the beginning of words. - * Note: unlike the specs for a WordBreakProc, this function only - * allows to be called without linebreaks between s[0] upto - * s[count - 1]. Remember it is only called - * internally, so we can decide this for ourselves. - * - */ -static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action) -{ - INT ret = 0; - - DPRINT( "s=%p, index=%u, count=%u, action=%d\n", - s, index, count, action); - - switch (action) { - case WB_LEFT: - if (!count) - break; - if (index) - index--; - if (s[index] == ' ') { - while (index && (s[index] == ' ')) - index--; - if (index) { - while (index && (s[index] != ' ')) - index--; - if (s[index] == ' ') - index++; - } - } else { - while (index && (s[index] != ' ')) - index--; - if (s[index] == ' ') - index++; - } - ret = index; - break; - case WB_RIGHT: - if (!count) - break; - if (index) - index--; - if (s[index] == ' ') - while ((index < count) && (s[index] == ' ')) index++; - else { - while (s[index] && (s[index] != ' ') && (index < count)) - index++; - while ((s[index] == ' ') && (index < count)) index++; - } - ret = index; - break; - case WB_ISDELIMITER: - ret = (s[index] == ' '); - break; - default: - DPRINT( "unknown action code, please report !\n"); - break; - } - return ret; -} - - -/********************************************************************* - * - * EM_CHARFROMPOS - * - * FIXME: do the specs mean to return LineIndex or LineNumber ??? - * Let's assume LineIndex is meant - * FIXME: do the specs mean to return -1 if outside client area or - * if outside formatting rectangle ??? - * - */ -static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT x, INT y) -{ - POINT pt; - RECT rc; - INT index; - - pt.x = x; - pt.y = y; - GetClientRect(wnd->hwndSelf, &rc); - if (!PtInRect(&rc, pt)) - return -1; - - index = EDIT_CharFromPos(wnd, es, x, y, NULL); - return MAKELONG(index, EDIT_EM_LineIndex(wnd, es, - EDIT_EM_LineFromChar(wnd, es, index))); -} - - -/********************************************************************* - * - * EM_FMTLINES - * - * Enable or disable soft breaks. - */ -static BOOL EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL add_eol) -{ - es->flags &= ~EF_USE_SOFTBRK; - if (add_eol) { - es->flags |= EF_USE_SOFTBRK; - DPRINT( "soft break enabled, not implemented\n"); - } - return add_eol; -} - - -/********************************************************************* - * - * EM_GETHANDLE - * - * Hopefully this won't fire back at us. - * We always start with a fixed buffer in our own heap. - * However, with this message a bit application requests - * a handle to bit moveable local heap memory, where it expects - * to find the text. - * It's a pity that from this moment on we have to use this - * local heap, because applications may rely on the handle - * in the future. - * - * In this function we'll try to switch to local heap. - * - */ -static HLOCAL EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es) -{ - HLOCAL newBuf; - LPSTR newText; - INT newSize; - - if (!(es->style & ES_MULTILINE)) - return 0; - - if (es->hloc) - return es->hloc; - - - if (!(newBuf = LocalAlloc(LMEM_MOVEABLE, lstrlenA(es->text) + 1))) { - DPRINT( "could not allocate new bit buffer\n"); - return 0; - } - newSize = min(LocalSize(newBuf) - 1, es->buffer_limit); - if (!(newText = LocalLock(newBuf))) { - DPRINT( "could not lock new bit buffer\n"); - LocalFree(newBuf); - return 0; - } - lstrcpyA(newText, es->text); - EDIT_UnlockBuffer(wnd, es, TRUE); - if (es->text) - HeapFree(es->heap, 0, es->text); - es->hloc = newBuf; - es->buffer_size = newSize; - es->text = newText; - EDIT_LockBuffer(wnd, es); - DPRINT( "switched to bit local heap\n"); - - return es->hloc; -} - - - - -/********************************************************************* - * - * EM_GETLINE - * - */ -static INT EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT line, LPSTR lpch) -{ - LPSTR src; - INT len; - INT i; - - if (es->style & ES_MULTILINE) { - if (line >= es->line_count) - return 0; - } else - line = 0; - i = EDIT_EM_LineIndex(wnd, es, line); - src = es->text + i; - len = min(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, i)); - for (i = 0 ; i < len ; i++) { - *lpch = *src; - src++; - lpch++; - } - return (LRESULT)len; -} - - -/********************************************************************* - * - * EM_GETSEL - * - */ -static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, UINT * start, UINT * end) -{ - UINT s = es->selection_start; - UINT e = es->selection_end; - - ORDER_UINT(s, e); - if (start) - *start = s; - if (end) - *end = e; - return MAKELONG(s, e); -} - - -/********************************************************************* - * - * EM_GETTHUMB - * - * FIXME: is this right ? (or should it be only VSCROLL) - * (and maybe only for edit controls that really have their - * own scrollbars) (and maybe only for multiline controls ?) - * All in all: very poorly documented - * - * FIXME: now it's also broken, because of the new WM_HSCROLL / - * WM_VSCROLL handlers - * - */ -static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es) -{ - return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB, 0, 0), - EDIT_WM_HScroll(wnd, es, EM_GETTHUMB, 0, 0)); -} - - -/********************************************************************* - * - * EM_LINEFROMCHAR - * - */ -static INT EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT index) -{ - INT line; - LINEDEF *line_def; - - if (!(es->style & ES_MULTILINE)) - return 0; - if (index > lstrlenA(es->text)) - return es->line_count - 1; - if (index == -1) - index = min(es->selection_start, es->selection_end); - - line = 0; - line_def = es->first_line_def; - index -= line_def->length; - while ((index >= 0) && line_def->next) { - line++; - line_def = line_def->next; - index -= line_def->length; - } - return line; -} - - -/********************************************************************* - * - * EM_LINEINDEX - * - */ -static INT EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT line) -{ - INT line_index; - LINEDEF *line_def; - - if (!(es->style & ES_MULTILINE)) - return 0; - if (line >= es->line_count) - return -1; - - line_index = 0; - line_def = es->first_line_def; - if (line == -1) { - INT index = es->selection_end - line_def->length; - while ((index >= 0) && line_def->next) { - line_index += line_def->length; - line_def = line_def->next; - index -= line_def->length; - } - } else { - while (line > 0) { - line_index += line_def->length; - line_def = line_def->next; - line--; - } - } - return line_index; -} - - -/********************************************************************* - * - * EM_LINELENGTH - * - */ -static INT EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT index) -{ - LINEDEF *line_def; - - if (!(es->style & ES_MULTILINE)) - return lstrlenA(es->text); - - if (index == -1) { - /* FIXME: broken - INT sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start); - INT el = EDIT_EM_LineFromChar(wnd, es, es->selection_end); - return es->selection_start - es->line_defs[sl].offset + - es->line_defs[el].offset + - es->line_defs[el].length - es->selection_end; - */ - return 0; - } - line_def = es->first_line_def; - index -= line_def->length; - while ((index >= 0) && line_def->next) { - line_def = line_def->next; - index -= line_def->length; - } - return line_def->net_length; -} - - -/********************************************************************* - * - * EM_LINESCROLL - * - * FIXME: dx is in average character widths - * However, we assume it is in pixels when we use this - * function internally - * - */ -static BOOL EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT dx, INT dy) -{ - INT nyoff; - - if (!(es->style & ES_MULTILINE)) - return FALSE; - - if (-dx > es->x_offset) - dx = -es->x_offset; - if (dx > es->text_width - es->x_offset) - dx = es->text_width - es->x_offset; - nyoff = max(0, es->y_offset + dy); - if (nyoff >= es->line_count) - nyoff = es->line_count - 1; - dy = (es->y_offset - nyoff) * es->line_height; - if (dx || dy) { - RECT rc1; - RECT rc; - GetClientRect(wnd->hwndSelf, &rc1); - IntersectRect(&rc, &rc1, &es->format_rect); - ScrollWindowEx(wnd->hwndSelf, -dx, dy, - NULL, &rc, (HRGN)NULL, NULL, SW_INVALIDATE); - es->y_offset = nyoff; - es->x_offset += dx; - } - if (dx && !(es->flags & EF_HSCROLL_TRACK)) - EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); - if (dy && !(es->flags & EF_VSCROLL_TRACK)) - EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); - return TRUE; -} - - -/********************************************************************* - * - * EM_POSFROMCHAR - * - */ -static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT index, BOOL after_wrap) -{ - INT len = lstrlenA(es->text); - INT l; - INT li; - INT x; - INT y = 0; - HDC dc; - HFONT old_font = 0; - SIZE size; - - index = min(index, len); - dc = GetDC(wnd->hwndSelf); - if (es->font) - old_font = SelectObject(dc, es->font); - if (es->style & ES_MULTILINE) { - l = EDIT_EM_LineFromChar(wnd, es, index); - y = (l - es->y_offset) * es->line_height; - li = EDIT_EM_LineIndex(wnd, es, l); - if (after_wrap && (li == index) && l) { - INT l2 = l - 1; - LINEDEF *line_def = es->first_line_def; - while (l2) { - line_def = line_def->next; - l2--; - } - if (line_def->ending == END_WRAP) { - l--; - y -= es->line_height; - li = EDIT_EM_LineIndex(wnd, es, l); - } - } - x = LOWORD(GetTabbedTextExtentA(dc, es->text + li, index - li, - es->tabs_count, es->tabs)) - es->x_offset; - } else { - LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es); - if (index < es->x_offset) { - GetTextExtentPointA(dc, text + index, - es->x_offset - index, &size); - x = -size.cx; - } else { - GetTextExtentPointA(dc, text + es->x_offset, - index - es->x_offset, &size); - x = size.cx; - } - y = 0; - if (es->style & ES_PASSWORD) - HeapFree(es->heap, 0 ,text); - } - x += es->format_rect.left; - y += es->format_rect.top; - if (es->font) - SelectObject(dc, old_font); - ReleaseDC(wnd->hwndSelf, dc); - return MAKELONG((INT)x, (INT)y); -} - - -/********************************************************************* - * - * EM_REPLACESEL - * - * FIXME: handle ES_NUMBER and ES_OEMCONVERT here - * - */ -static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace) -{ - INT strl = lstrlenA(lpsz_replace); - INT tl = lstrlenA(es->text); - INT utl; - UINT s; - UINT e; - INT i; - LPSTR p; - - s = es->selection_start; - e = es->selection_end; - - if ((s == e) && !strl) - return; - - ORDER_UINT(s, e); - - if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl)) - return; - - if (e != s) { - /* there is something to be deleted */ - if (can_undo) { - utl = lstrlenA(es->undo_text); - if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) { - /* undo-buffer is extended to the right */ - EDIT_MakeUndoFit(wnd, es, utl + e - s); - lstrcpynA(es->undo_text + utl, es->text + s, e - s + 1); - } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) { - /* undo-buffer is extended to the left */ - EDIT_MakeUndoFit(wnd, es, utl + e - s); - for (p = es->undo_text + utl ; p >= es->undo_text ; p--) - p[e - s] = p[0]; - for (i = 0 , p = es->undo_text ; i < e - s ; i++) - p[i] = (es->text + s)[i]; - es->undo_position = s; - } else { - /* new undo-buffer */ - EDIT_MakeUndoFit(wnd, es, e - s); - lstrcpynA(es->undo_text, es->text + s, e - s + 1); - es->undo_position = s; - } - /* any deletion makes the old insertion-undo invalid */ - es->undo_insert_count = 0; - } else - EDIT_EM_EmptyUndoBuffer(wnd, es); - - /* now delete */ - lstrcpyA(es->text + s, es->text + e); - } - if (strl) { - /* there is an insertion */ - if (can_undo) { - if ((s == es->undo_position) || - ((es->undo_insert_count) && - (s == es->undo_position + es->undo_insert_count))) - /* - * insertion is new and at delete position or - * an extension to either left or right - */ - es->undo_insert_count += strl; - else { - /* new insertion undo */ - es->undo_position = s; - es->undo_insert_count = strl; - /* new insertion makes old delete-buffer invalid */ - *es->undo_text = '\0'; - } - } else - EDIT_EM_EmptyUndoBuffer(wnd, es); - - /* now insert */ - tl = lstrlenA(es->text); - for (p = es->text + tl ; p >= es->text + s ; p--) - p[strl] = p[0]; - for (i = 0 , p = es->text + s ; i < strl ; i++) - p[i] = lpsz_replace[i]; - if(es->style & ES_UPPERCASE) - CharUpperBuffA(p, strl); - else if(es->style & ES_LOWERCASE) - CharLowerBuffA(p, strl); - s += strl; - } - /* FIXME: really inefficient */ - if (es->style & ES_MULTILINE) - EDIT_BuildLineDefs_ML(wnd, es); - - EDIT_EM_SetSel(wnd, es, s, s, FALSE); - es->flags |= EF_MODIFIED; - es->flags |= EF_UPDATE; - EDIT_EM_ScrollCaret(wnd, es); - - /* FIXME: really inefficient */ - InvalidateRect(wnd->hwndSelf, NULL, TRUE); -} - - -/********************************************************************* - * - * EM_SCROLL - * - */ -static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT action) -{ - INT dy; - - if (!(es->style & ES_MULTILINE)) - return (LRESULT)FALSE; - - dy = 0; - - switch (action) { - case SB_LINEUP: - if (es->y_offset) - dy = -1; - break; - case SB_LINEDOWN: - if (es->y_offset < es->line_count - 1) - dy = 1; - break; - case SB_PAGEUP: - if (es->y_offset) - dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height; - break; - case SB_PAGEDOWN: - if (es->y_offset < es->line_count - 1) - dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height; - break; - default: - return (LRESULT)FALSE; - } - if (dy) { - EDIT_EM_LineScroll(wnd, es, 0, dy); - EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); - } - return MAKELONG((INT)dy, (BOOL)TRUE); -} - - -/********************************************************************* - * - * EM_SCROLLCARET - * - */ -static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es) -{ - if (es->style & ES_MULTILINE) { - INT l; - INT li; - INT vlc; - INT ww; - INT cw = es->char_width; - INT x; - INT dy = 0; - INT dx = 0; - - l = EDIT_EM_LineFromChar(wnd, es, es->selection_end); - li = EDIT_EM_LineIndex(wnd, es, l); - x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)); - vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; - if (l >= es->y_offset + vlc) - dy = l - vlc + 1 - es->y_offset; - if (l < es->y_offset) - dy = l - es->y_offset; - ww = es->format_rect.right - es->format_rect.left; - if (x < es->format_rect.left) - dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw; - if (x > es->format_rect.right) - dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw; - if (dy || dx) - EDIT_EM_LineScroll(wnd, es, dx, dy); - } else { - INT x; - INT goal; - INT format_width; - - if (!(es->style & ES_AUTOHSCROLL)) - return; - - x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); - format_width = es->format_rect.right - es->format_rect.left; - if (x < es->format_rect.left) { - goal = es->format_rect.left + format_width / HSCROLL_FRACTION; - do { - es->x_offset--; - x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); - } while ((x < goal) && es->x_offset); - /* FIXME: use ScrollWindow() somehow to improve performance */ - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - } else if (x > es->format_rect.right) { - INT x_last; - INT len = lstrlenA(es->text); - goal = es->format_rect.right - format_width / HSCROLL_FRACTION; - do { - es->x_offset++; - x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); - x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE)); - } while ((x > goal) && (x_last > es->format_rect.right)); - /* FIXME: use ScrollWindow() somehow to improve performance */ - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - } - } -} - - -/********************************************************************* - * - * EM_SETHANDLE - * - * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? - * - */ -static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL hloc) -{ - if (!(es->style & ES_MULTILINE)) - return; - - if (!hloc) { - DPRINT( "called with NULL handle\n"); - return; - } - - EDIT_UnlockBuffer(wnd, es, TRUE); - /* - * old buffer is freed by caller, unless - * it is still in our own heap. (in that case - * we free it, correcting the buggy caller.) - */ - if (es->text) - HeapFree(es->heap, 0, es->text); - - es->hloc = hloc; - es->text = NULL; - es->buffer_size = LocalSize(es->hloc) - 1; - EDIT_LockBuffer(wnd, es); - - es->x_offset = es->y_offset = 0; - es->selection_start = es->selection_end = 0; - EDIT_EM_EmptyUndoBuffer(wnd, es); - es->flags &= ~EF_MODIFIED; - es->flags &= ~EF_UPDATE; - EDIT_BuildLineDefs_ML(wnd, es); - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - EDIT_EM_ScrollCaret(wnd, es); -} - - - - - -/********************************************************************* - * - * EM_SETLIMITTEXT - * - * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF - * However, the windows version is not complied to yet in all of edit.c - * - */ -static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT limit) -{ - if (es->style & ES_MULTILINE) { - if (limit) - es->buffer_limit = min(limit, BUFLIMIT_MULTI); - else - es->buffer_limit = BUFLIMIT_MULTI; - } else { - if (limit) - es->buffer_limit = min(limit, BUFLIMIT_SINGLE); - else - es->buffer_limit = BUFLIMIT_SINGLE; - } -} - - -/********************************************************************* - * - * EM_SETMARGINS - * - * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an - * action wParam despite what the docs say. It also appears not to affect - * multiline controls?? - * - */ -static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT action, - INT left, INT right) -{ - if (action & EC_LEFTMARGIN) { - if (left != EC_USEFONTINFO) - es->left_margin = left; - else - if (es->style & ES_MULTILINE) - es->left_margin = 0; /* ?? */ - else - es->left_margin = es->char_width; - } - - if (action & EC_RIGHTMARGIN) { - if (right != EC_USEFONTINFO) - es->right_margin = right; - else - if (es->style & ES_MULTILINE) - es->right_margin = 0; /* ?? */ - else - es->right_margin = es->char_width; - } - DPRINT( "left=%d, right=%d\n", es->left_margin, es->right_margin); -} - - -/********************************************************************* - * - * EM_SETPASSWORDCHAR - * - */ -static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c) -{ - if (es->style & ES_MULTILINE) - return; - - if (es->password_char == c) - return; - - es->password_char = c; - if (c) { - wnd->dwStyle |= ES_PASSWORD; - es->style |= ES_PASSWORD; - } else { - wnd->dwStyle &= ~ES_PASSWORD; - es->style &= ~ES_PASSWORD; - } - InvalidateRect(wnd->hwndSelf, NULL, TRUE); -} - - -/********************************************************************* - * - * EDIT_EM_SetSel - * - * note: unlike the specs say: the order of start and end - * _is_ preserved in Windows. (i.e. start can be > end) - * In other words: this handler is OK - * - */ -static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap) -{ - UINT old_start = es->selection_start; - UINT old_end = es->selection_end; - UINT len = lstrlenA(es->text); - - if (start == -1) { - start = es->selection_end; - end = es->selection_end; - } else { - start = min(start, len); - end = min(end, len); - } - es->selection_start = start; - es->selection_end = end; - if (after_wrap) - es->flags |= EF_AFTER_WRAP; - else - es->flags &= ~EF_AFTER_WRAP; - if (es->flags & EF_FOCUSED) - EDIT_SetCaretPos(wnd, es, end, after_wrap); -/* This is little bit more efficient than before, not sure if it can be improved. FIXME? */ - ORDER_UINT(start, end); - ORDER_UINT(end, old_end); - ORDER_UINT(start, old_start); - ORDER_UINT(old_start, old_end); - if (end != old_start) - { -/* - * One can also do - * ORDER_UINT(end, old_start); - * EDIT_InvalidateText(wnd, es, start, end); - * EDIT_InvalidateText(wnd, es, old_start, old_end); - * in place of the following if statement. - */ - if (old_start > end ) - { - EDIT_InvalidateText(wnd, es, start, end); - EDIT_InvalidateText(wnd, es, old_start, old_end); - } - else - { - EDIT_InvalidateText(wnd, es, start, old_start); - EDIT_InvalidateText(wnd, es, end, old_end); - } - } - else EDIT_InvalidateText(wnd, es, start, old_end); -} - - -/********************************************************************* - * - * EM_SETTABSTOPS - * - */ -static BOOL EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT count, LPINT tabs) -{ - if (!(es->style & ES_MULTILINE)) - return FALSE; - if (es->tabs) - HeapFree(es->heap, 0, es->tabs); - es->tabs_count = count; - if (!count) - es->tabs = NULL; - else { - es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT)); - memcpy(es->tabs, tabs, count * sizeof(INT)); - } - return TRUE; -} - - - - -/********************************************************************* - * - * EM_SETWORDBREAKPROC - * - */ -static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp) -{ - if (es->word_break_procA == wbp) - return; - - es->word_break_procA = wbp; - if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { - EDIT_BuildLineDefs_ML(wnd, es); - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - } -} - - - - - -/********************************************************************* - * - * EM_UNDO / WM_UNDO - * - */ -static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es) -{ - INT ulength = lstrlenA(es->undo_text); - LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1); - - lstrcpyA(utext, es->undo_text); - - DPRINT( "before UNDO:insertion length = %d, deletion buffer = %s\n", - es->undo_insert_count, utext); - - EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); - EDIT_EM_EmptyUndoBuffer(wnd, es); - EDIT_EM_ReplaceSel(wnd, es, TRUE, utext); - EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); - HeapFree(es->heap, 0, utext); - - DPRINT( "after UNDO:insertion length = %d, deletion buffer = %s\n", - es->undo_insert_count, es->undo_text); - - return TRUE; -} - - -/********************************************************************* - * - * WM_CHAR - * - */ -static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data) -{ - switch (c) { - case '\r': - case '\n': - if (es->style & ES_MULTILINE) { - if (es->style & ES_READONLY) { - EDIT_MoveHome(wnd, es, FALSE); - EDIT_MoveDown_ML(wnd, es, FALSE); - } else - EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n"); - } - break; - case '\t': - if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) - EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t"); - break; - default: - if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) { - char str[2]; - str[0] = c; - str[1] = '\0'; - EDIT_EM_ReplaceSel(wnd, es, TRUE, str); - } - break; - } -} - - -/********************************************************************* - * - * WM_COMMAND - * - */ -static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT code, INT id, HWND control) -{ - if (code || control) - return; - - switch (id) { - case EM_UNDO: - EDIT_EM_Undo(wnd, es); - break; - case WM_CUT: - EDIT_WM_Cut(wnd, es); - break; - case WM_COPY: - EDIT_WM_Copy(wnd, es); - break; - case WM_PASTE: - EDIT_WM_Paste(wnd, es); - break; - case WM_CLEAR: - EDIT_WM_Clear(wnd, es); - break; - case EM_SETSEL: - EDIT_EM_SetSel(wnd, es, 0, -1, FALSE); - EDIT_EM_ScrollCaret(wnd, es); - break; - default: - DPRINT( "unknown menu item, please report\n"); - break; - } -} - - -/********************************************************************* - * - * WM_CONTEXTMENU - * - * Note: the resource files resource/sysres_??.rc cannot define a - * single popup menu. Hence we use a (dummy) menubar - * containing the single popup menu as its first item. - * - * FIXME: the message identifiers have been chosen arbitrarily, - * hence we use MF_BYPOSITION. - * We might as well use the "real" values (anybody knows ?) - * The menu definition is in resources/sysres_??.rc. - * Once these are OK, we better use MF_BYCOMMAND here - * (as we do in EDIT_WM_Command()). - * - */ -static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND hwnd, INT x, INT y) -{ - HMENU menu = LoadMenuIndirectA(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU)); - HMENU popup = GetSubMenu(menu, 0); - UINT start = es->selection_start; - UINT end = es->selection_end; - - ORDER_UINT(start, end); - - /* undo */ - EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(wnd, es) ? MF_ENABLED : MF_GRAYED)); - /* cut */ - EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); - /* copy */ - EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); - /* paste */ - EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED)); - /* delete */ - EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED)); - /* select all */ - EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != lstrlenA(es->text)) ? MF_ENABLED : MF_GRAYED)); - - TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL); - DestroyMenu(menu); -} - - -/********************************************************************* - * - * WM_COPY - * - */ -static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es) -{ - INT s = es->selection_start; - INT e = es->selection_end; - HGLOBAL hdst; - LPSTR dst; - - if (e == s) - return; - ORDER_INT(s, e); - hdst = GlobalAlloc(GMEM_MOVEABLE, (DWORD)(e - s + 1)); - dst = GlobalLock(hdst); - lstrcpynA(dst, es->text + s, e - s + 1); - GlobalUnlock(hdst); - OpenClipboard(wnd->hwndSelf); - EmptyClipboard(); - SetClipboardData(CF_TEXT, hdst); - CloseClipboard(); -} - - -/********************************************************************* - * - * WM_CREATE - * - */ -static LRESULT EDIT_WM_Create(WND *wnd, EDITSTATE *es, LPCREATESTRUCT cs) -{ - /* - * To initialize some final structure members, we call some helper - * functions. However, since the EDITSTATE is not consistent (i.e. - * not fully initialized), we should be very careful which - * functions can be called, and in what order. - */ - EDIT_WM_SetFont(wnd, es, 0, FALSE); - if (cs->lpszName && *(cs->lpszName) != '\0') { - EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName); - /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */ - es->selection_start = es->selection_end = 0; - EDIT_EM_ScrollCaret(wnd, es); - } - return 0; -} - - -/********************************************************************* - * - * WM_DESTROY - * - */ -static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es) -{ - if (es->hloc) { - while (LocalUnlock(es->hloc)) ; - LocalFree(es->hloc); - } - - HeapDestroy(es->heap); - HeapFree(GetProcessHeap(), 0, es); - *(EDITSTATE **)wnd->wExtra = NULL; -} - - -/********************************************************************* - * - * WM_ERASEBKGND - * - */ -static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC dc) -{ - HBRUSH brush; - RECT rc; - - if (!(brush = (HBRUSH)EDIT_SEND_CTLCOLOR(wnd, dc))) - brush = (HBRUSH)GetStockObject(WHITE_BRUSH); - - GetClientRect(wnd->hwndSelf, &rc); - IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom); - GetClipBox(dc, &rc); - /* - * FIXME: specs say that we should UnrealizeObject() the brush, - * but the specs of UnrealizeObject() say that we shouldn't - * unrealize a stock object. The default brush that - * DefWndProc() returns is ... a stock object. - */ - FillRect(dc, &rc, brush); - return -1; -} - - -/********************************************************************* - * - * WM_GETTEXT - * - */ -static INT EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT count, LPSTR text) -{ - INT len = lstrlenA(es->text); - - if (count > len) { - lstrcpyA(text, es->text); - return len; - } else - return -1; -} - - -/********************************************************************* - * - * EDIT_HScroll_Hack - * - * 16 bit notepad needs this. Actually it is not _our_ hack, - * it is notepad's. Notepad is sending us scrollbar messages with - * undocumented parameters without us even having a scrollbar ... !?!? - * - */ -static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) -{ - INT dx = 0; - INT fw = es->format_rect.right - es->format_rect.left; - LRESULT ret = 0; - - if (!(es->flags & EF_HSCROLL_HACK)) { - DPRINT( "hacked WM_HSCROLL handler invoked\n"); - DPRINT( " if you are _not_ running 16 bit notepad, please report\n"); - DPRINT( " (this message is only displayed once per edit control)\n"); - es->flags |= EF_HSCROLL_HACK; - } - - switch (action) { - case SB_LINELEFT: - if (es->x_offset) - dx = -es->char_width; - break; - case SB_LINERIGHT: - if (es->x_offset < es->text_width) - dx = es->char_width; - break; - case SB_PAGELEFT: - if (es->x_offset) - dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; - break; - case SB_PAGERIGHT: - if (es->x_offset < es->text_width) - dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; - break; - case SB_LEFT: - if (es->x_offset) - dx = -es->x_offset; - break; - case SB_RIGHT: - if (es->x_offset < es->text_width) - dx = es->text_width - es->x_offset; - break; - case SB_THUMBTRACK: - es->flags |= EF_HSCROLL_TRACK; - dx = pos * es->text_width / 100 - es->x_offset; - break; - case SB_THUMBPOSITION: - es->flags &= ~EF_HSCROLL_TRACK; - if (!(dx = pos * es->text_width / 100 - es->x_offset)) - EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); - break; - case SB_ENDSCROLL: - break; - - /* - * FIXME : the next two are undocumented ! - * Are we doing the right thing ? - * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, - * although it's also a regular control message. - */ - case EM_GETTHUMB: - ret = es->text_width ? es->x_offset * 100 / es->text_width : 0; - break; - case EM_LINESCROLL: - dx = pos; - break; - - default: - DPRINT( "undocumented (hacked) WM_HSCROLL parameter, please report\n"); - return 0; - } - if (dx) - EDIT_EM_LineScroll(wnd, es, dx, 0); - return ret; -} - - -/********************************************************************* - * - * WM_HSCROLL - * - */ -static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) -{ - INT dx; - INT fw; - - if (!(es->style & ES_MULTILINE)) - return 0; - - if (!(es->style & ES_AUTOHSCROLL)) - return 0; - - if (!(es->style & WS_HSCROLL)) - return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar); - - dx = 0; - fw = es->format_rect.right - es->format_rect.left; - switch (action) { - case SB_LINELEFT: - if (es->x_offset) - dx = -es->char_width; - break; - case SB_LINERIGHT: - if (es->x_offset < es->text_width) - dx = es->char_width; - break; - case SB_PAGELEFT: - if (es->x_offset) - dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; - break; - case SB_PAGERIGHT: - if (es->x_offset < es->text_width) - dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; - break; - case SB_LEFT: - if (es->x_offset) - dx = -es->x_offset; - break; - case SB_RIGHT: - if (es->x_offset < es->text_width) - dx = es->text_width - es->x_offset; - break; - case SB_THUMBTRACK: - es->flags |= EF_HSCROLL_TRACK; - dx = pos - es->x_offset; - break; - case SB_THUMBPOSITION: - es->flags &= ~EF_HSCROLL_TRACK; - if (!(dx = pos - es->x_offset)) { - SetScrollPos(wnd->hwndSelf, SB_HORZ, pos, TRUE); - EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); - } - break; - case SB_ENDSCROLL: - break; - - default: - DPRINT( "undocumented WM_HSCROLL parameter, please report\n"); - return 0; - } - if (dx) - EDIT_EM_LineScroll(wnd, es, dx, 0); - return 0; -} - - -/********************************************************************* - * - * EDIT_CheckCombo - * - */ -static BOOL EDIT_CheckCombo(WND *wnd, UINT msg, INT key, DWORD key_data) -{ - HWND hLBox; - - if (WIDGETS_IsControl(wnd->parent, BIC_COMBO) && - (hLBox = COMBO_GetLBWindow(wnd->parent))) { - HWND hCombo = wnd->parent->hwndSelf; - BOOL bUIFlip = TRUE; - - DPRINT( "[%04x]: handling msg %04x (%04x)\n", - wnd->hwndSelf, (UINT)msg, (UINT)key); - - switch (msg) { - case WM_KEYDOWN: /* Handle F4 and arrow keys */ - if (key != VK_F4) { - bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0); - if (SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0)) - bUIFlip = FALSE; - } - if (!bUIFlip) - SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)key, 0); - else { - /* make sure ComboLBox pops up */ - SendMessageA(hCombo, CB_SETEXTENDEDUI, 0, 0); - SendMessageA(hLBox, WM_KEYDOWN, VK_F4, 0); - SendMessageA(hCombo, CB_SETEXTENDEDUI, 1, 0); - } - break; - case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */ - bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0); - if (bUIFlip) { - bUIFlip = (BOOL)SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0); - SendMessageA(hCombo, CB_SHOWDROPDOWN, (bUIFlip) ? FALSE : TRUE, 0); - } else - SendMessageA(hLBox, WM_KEYDOWN, VK_F4, 0); - break; - } - return TRUE; - } - return FALSE; -} - - -/********************************************************************* - * - * WM_KEYDOWN - * - * Handling of special keys that don't produce a WM_CHAR - * (i.e. non-printable keys) & Backspace & Delete - * - */ -static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data) -{ - BOOL shift; - BOOL control; - - if (GetKeyState(VK_MENU) & 0x8000) - return 0; - - shift = GetKeyState(VK_SHIFT) & 0x8000; - control = GetKeyState(VK_CONTROL) & 0x8000; - - switch (key) { - case VK_F4: - case VK_UP: - if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data)) - break; - if (key == VK_F4) - break; - /* fall through */ - case VK_LEFT: - if ((es->style & ES_MULTILINE) && (key == VK_UP)) - EDIT_MoveUp_ML(wnd, es, shift); - else - if (control) - EDIT_MoveWordBackward(wnd, es, shift); - else - EDIT_MoveBackward(wnd, es, shift); - break; - case VK_DOWN: - if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data)) - break; - /* fall through */ - case VK_RIGHT: - if ((es->style & ES_MULTILINE) && (key == VK_DOWN)) - EDIT_MoveDown_ML(wnd, es, shift); - else if (control) - EDIT_MoveWordForward(wnd, es, shift); - else - EDIT_MoveForward(wnd, es, shift); - break; - case VK_HOME: - EDIT_MoveHome(wnd, es, shift); - break; - case VK_END: - EDIT_MoveEnd(wnd, es, shift); - break; - case VK_PRIOR: - if (es->style & ES_MULTILINE) - EDIT_MovePageUp_ML(wnd, es, shift); - break; - case VK_NEXT: - if (es->style & ES_MULTILINE) - EDIT_MovePageDown_ML(wnd, es, shift); - break; - case VK_BACK: - if (!(es->style & ES_READONLY) && !control) { - if (es->selection_start != es->selection_end) - EDIT_WM_Clear(wnd, es); - else { - /* delete character left of caret */ - EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); - EDIT_MoveBackward(wnd, es, TRUE); - EDIT_WM_Clear(wnd, es); - } - } - break; - case VK_DELETE: - if (!(es->style & ES_READONLY) && !(shift && control)) { - if (es->selection_start != es->selection_end) { - if (shift) - EDIT_WM_Cut(wnd, es); - else - EDIT_WM_Clear(wnd, es); - } else { - if (shift) { - /* delete character left of caret */ - EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); - EDIT_MoveBackward(wnd, es, TRUE); - EDIT_WM_Clear(wnd, es); - } else if (control) { - /* delete to end of line */ - EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); - EDIT_MoveEnd(wnd, es, TRUE); - EDIT_WM_Clear(wnd, es); - } else { - /* delete character right of caret */ - EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); - EDIT_MoveForward(wnd, es, TRUE); - EDIT_WM_Clear(wnd, es); - } - } - } - break; - case VK_INSERT: - if (shift) { - if (!(es->style & ES_READONLY)) - EDIT_WM_Paste(wnd, es); - } else if (control) - EDIT_WM_Copy(wnd, es); - break; - } - return 0; -} - - -/********************************************************************* - * - * WM_KILLFOCUS - * - */ -static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND window_getting_focus) -{ - es->flags &= ~EF_FOCUSED; - DestroyCaret(); - if(!(es->style & ES_NOHIDESEL)) - EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end); - EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS"); - return 0; -} - - -/********************************************************************* - * - * WM_LBUTTONDBLCLK - * - * The caret position has been set on the WM_LBUTTONDOWN message - * - */ -static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y) -{ - INT s; - INT e = es->selection_end; - INT l; - INT li; - INT ll; - - if (!(es->flags & EF_FOCUSED)) - return 0; - - l = EDIT_EM_LineFromChar(wnd, es, e); - li = EDIT_EM_LineIndex(wnd, es, l); - ll = EDIT_EM_LineLength(wnd, es, e); - s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT); - e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT); - EDIT_EM_SetSel(wnd, es, s, e, FALSE); - EDIT_EM_ScrollCaret(wnd, es); - return 0; -} - - -/********************************************************************* - * - * WM_LBUTTONDOWN - * - */ -static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y) -{ - INT e; - BOOL after_wrap; - - if (!(es->flags & EF_FOCUSED)) - return 0; - - SetCapture(wnd->hwndSelf); - EDIT_ConfinePoint(wnd, es, &x, &y); - e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap); - EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap); - EDIT_EM_ScrollCaret(wnd, es); - es->region_posx = es->region_posy = 0; - SetTimer(wnd->hwndSelf, 0, 100, NULL); - return 0; -} - - -/********************************************************************* - * - * WM_LBUTTONUP - * - */ -static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y) -{ - if (GetCapture() == wnd->hwndSelf) { - KillTimer(wnd->hwndSelf, 0); - ReleaseCapture(); - } - return 0; -} - - -/********************************************************************* - * - * WM_MOUSEMOVE - * - */ -static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT x, INT y) -{ - INT e; - BOOL after_wrap; - INT prex, prey; - - if (GetCapture() != wnd->hwndSelf) - return 0; - - /* - * FIXME: gotta do some scrolling if outside client - * area. Maybe reset the timer ? - */ - prex = x; prey = y; - EDIT_ConfinePoint(wnd, es, &x, &y); - es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0); - es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0); - e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap); - EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap); - return 0; -} - - -/********************************************************************* - * - * WM_NCCREATE - * - */ -static LRESULT EDIT_WM_NCCreate(WND *wnd, LPCREATESTRUCT cs) -{ - EDITSTATE *es; - - if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es)))) - return FALSE; - *(EDITSTATE **)wnd->wExtra = es; - - /* - * Note: since the EDITSTATE has not been fully initialized yet, - * we can't use any API calls that may send - * WM_XXX messages before WM_NCCREATE is completed. - */ - - if (!(es->heap = HeapCreate(0, 0x10000, 0))) - return FALSE; - es->style = cs->style; - - if ((es->style & WS_BORDER) && !(es->style & WS_DLGFRAME)) - wnd->dwStyle &= ~WS_BORDER; - - if (es->style & ES_MULTILINE) { - es->buffer_size = BUFSTART_MULTI; - es->buffer_limit = BUFLIMIT_MULTI; - if (es->style & WS_VSCROLL) - es->style |= ES_AUTOVSCROLL; - if (es->style & WS_HSCROLL) - es->style |= ES_AUTOHSCROLL; - es->style &= ~ES_PASSWORD; - if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) { - if (es->style & ES_RIGHT) - es->style &= ~ES_CENTER; - es->style &= ~WS_HSCROLL; - es->style &= ~ES_AUTOHSCROLL; - } - - /* FIXME: for now, all multi line controls are AUTOVSCROLL */ - es->style |= ES_AUTOVSCROLL; - } else { - es->buffer_size = BUFSTART_SINGLE; - es->buffer_limit = BUFLIMIT_SINGLE; - es->style &= ~ES_CENTER; - es->style &= ~ES_RIGHT; - es->style &= ~WS_HSCROLL; - es->style &= ~WS_VSCROLL; - es->style &= ~ES_AUTOVSCROLL; - es->style &= ~ES_WANTRETURN; - if (es->style & ES_UPPERCASE) { - es->style &= ~ES_LOWERCASE; - es->style &= ~ES_NUMBER; - } else if (es->style & ES_LOWERCASE) - es->style &= ~ES_NUMBER; - if (es->style & ES_PASSWORD) - es->password_char = '*'; - - /* FIXME: for now, all single line controls are AUTOHSCROLL */ - es->style |= ES_AUTOHSCROLL; - } - if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1))) - return FALSE; - es->buffer_size = HeapSize(es->heap, 0, es->text) - 1; - if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1))) - return FALSE; - es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; - *es->text = '\0'; - if (es->style & ES_MULTILINE) - if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF)))) - return FALSE; - es->line_count = 1; - - return TRUE; -} - -/********************************************************************* - * - * WM_PAINT - * - */ -static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es) -{ - PAINTSTRUCT ps; - INT i; - HDC dc; - HFONT old_font = 0; - RECT rc; - RECT rcLine; - RECT rcRgn; - BOOL rev = IsWindowEnabled(wnd->hwndSelf) && - ((es->flags & EF_FOCUSED) || - (es->style & ES_NOHIDESEL)); - - if (es->flags & EF_UPDATE) - EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE"); - - dc = BeginPaint(wnd->hwndSelf, &ps); - if(es->style & WS_BORDER) { - GetClientRect(wnd->hwndSelf, &rc); - if(es->style & ES_MULTILINE) { - if(es->style & WS_HSCROLL) rc.bottom++; - if(es->style & WS_VSCROLL) rc.right++; - } - Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom); - } - IntersectClipRect(dc, es->format_rect.left, - es->format_rect.top, - es->format_rect.right, - es->format_rect.bottom); - if (es->style & ES_MULTILINE) { - GetClientRect(wnd->hwndSelf, &rc); - IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom); - } - if (es->font) - old_font = SelectObject(dc, es->font); - EDIT_SEND_CTLCOLOR(wnd, dc); - if (!IsWindowEnabled(wnd->hwndSelf)) - SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT)); - GetClipBox(dc, &rcRgn); - if (es->style & ES_MULTILINE) { - INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; - for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) { - EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine); - if (IntersectRect(&rc, &rcRgn, &rcLine)) - EDIT_PaintLine(wnd, es, dc, i, rev); - } - } else { - EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine); - if (IntersectRect(&rc, &rcRgn, &rcLine)) - EDIT_PaintLine(wnd, es, dc, 0, rev); - } - if (es->font) - SelectObject(dc, old_font); - if (es->flags & EF_FOCUSED) - EDIT_SetCaretPos(wnd, es, es->selection_end, - es->flags & EF_AFTER_WRAP); - EndPaint(wnd->hwndSelf, &ps); - if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) { - INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; - SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; - si.nMin = 0; - si.nMax = es->line_count + vlc - 2; - si.nPage = vlc; - si.nPos = es->y_offset; - SetScrollInfo(wnd->hwndSelf, SB_VERT, &si, TRUE); - } - if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) { - SCROLLINFO si; - INT fw = es->format_rect.right - es->format_rect.left; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; - si.nMin = 0; - si.nMax = es->text_width + fw - 1; - si.nPage = fw; - si.nPos = es->x_offset; - SetScrollInfo(wnd->hwndSelf, SB_HORZ, &si, TRUE); - } - - if (es->flags & EF_UPDATE) { - es->flags &= ~EF_UPDATE; - EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE"); - } -} - - -/********************************************************************* - * - * WM_PASTE - * - */ -static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es) -{ - HGLOBAL hsrc; - LPSTR src; - - OpenClipboard(wnd->hwndSelf); - if ((hsrc = GetClipboardData(CF_TEXT))) { - src = (LPSTR)GlobalLock(hsrc); - EDIT_EM_ReplaceSel(wnd, es, TRUE, src); - GlobalUnlock(hsrc); - } - CloseClipboard(); -} - - -/********************************************************************* - * - * WM_SETFOCUS - * - */ -static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND window_losing_focus) -{ - es->flags |= EF_FOCUSED; - CreateCaret(wnd->hwndSelf, 0, 2, es->line_height); - EDIT_SetCaretPos(wnd, es, es->selection_end, - es->flags & EF_AFTER_WRAP); - if(!(es->style & ES_NOHIDESEL)) - EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end); - ShowCaret(wnd->hwndSelf); - EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS"); -} - - -/********************************************************************* - * - * WM_SETFONT - * - * With Win95 look the margins are set to default font value unless - * the system font (font == 0) is being set, in which case they are left - * unchanged. - * - */ -static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT font, BOOL redraw) -{ - TEXTMETRIC tm; - HDC dc; - HFONT old_font = 0; - - es->font = font; - dc = GetDC(wnd->hwndSelf); - if (font) - old_font = SelectObject(dc, font); - GetTextMetricsA(dc, &tm); - es->line_height = tm.tmHeight; - es->char_width = tm.tmAveCharWidth; - if (font) - SelectObject(dc, old_font); - ReleaseDC(wnd->hwndSelf, dc); - if (font && (TWEAK_WineLook > WIN31_LOOK)) - EDIT_EM_SetMargins(wnd, es, EC_LEFTMARGIN | EC_RIGHTMARGIN, - EC_USEFONTINFO, EC_USEFONTINFO); - if (es->style & ES_MULTILINE) - EDIT_BuildLineDefs_ML(wnd, es); - else { - RECT r; - GetClientRect(wnd->hwndSelf, &r); - EDIT_SetRectNP(wnd, es, &r); - } - if (redraw) - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - if (es->flags & EF_FOCUSED) { - DestroyCaret(); - CreateCaret(wnd->hwndSelf, 0, 2, es->line_height); - EDIT_SetCaretPos(wnd, es, es->selection_end, - es->flags & EF_AFTER_WRAP); - ShowCaret(wnd->hwndSelf); - } -} - - -/********************************************************************* - * - * WM_SETTEXT - * - * NOTES - * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers: - * The modified flag is reset. No notifications are sent. - * - * For single-line controls, reception of WM_SETTEXT triggers: - * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent. - * - */ -static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text) -{ - EDIT_EM_SetSel(wnd, es, 0, -1, FALSE); - if (text) { - DPRINT( "\t'%s'\n", text); - EDIT_EM_ReplaceSel(wnd, es, FALSE, text); - } else { - DPRINT( "\t\n"); - EDIT_EM_ReplaceSel(wnd, es, FALSE, ""); - } - es->x_offset = 0; - if (es->style & ES_MULTILINE) { - es->flags &= ~EF_UPDATE; - } else { - es->flags |= EF_UPDATE; - } - es->flags &= ~EF_MODIFIED; - EDIT_EM_SetSel(wnd, es, 0, 0, FALSE); - EDIT_EM_ScrollCaret(wnd, es); -} - - -/********************************************************************* - * - * WM_SIZE - * - */ -static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT action, INT width, INT height) -{ - if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) { - RECT rc; - SetRect(&rc, 0, 0, width, height); - EDIT_SetRectNP(wnd, es, &rc); - InvalidateRect(wnd->hwndSelf, NULL, TRUE); - } -} - - -/********************************************************************* - * - * WM_SYSKEYDOWN - * - */ -static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT key, DWORD key_data) -{ - if ((key == VK_BACK) && (key_data & 0x2000)) { - if (EDIT_EM_CanUndo(wnd, es)) - EDIT_EM_Undo(wnd, es); - return 0; - } else if (key == VK_UP || key == VK_DOWN) - if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data)) - return 0; - return DefWindowProcA(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data); -} - - -/********************************************************************* - * - * WM_TIMER - * - */ -static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT id, TIMERPROC timer_proc) -{ - if (es->region_posx < 0) { - EDIT_MoveBackward(wnd, es, TRUE); - } else if (es->region_posx > 0) { - EDIT_MoveForward(wnd, es, TRUE); - } -/* - * FIXME: gotta do some vertical scrolling here, like - * EDIT_EM_LineScroll(wnd, 0, 1); - */ -} - - -/********************************************************************* - * - * EDIT_VScroll_Hack - * - * 16 bit notepad needs this. Actually it is not _our_ hack, - * it is notepad's. Notepad is sending us scrollbar messages with - * undocumented parameters without us even having a scrollbar ... !?!? - * - */ -static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) -{ - INT dy = 0; - LRESULT ret = 0; - - if (!(es->flags & EF_VSCROLL_HACK)) { - DPRINT( "hacked WM_VSCROLL handler invoked\n"); - DPRINT( " if you are _not_ running 16 bit notepad, please report\n"); - DPRINT( " (this message is only displayed once per edit control)\n"); - es->flags |= EF_VSCROLL_HACK; - } - - switch (action) { - case SB_LINEUP: - case SB_LINEDOWN: - case SB_PAGEUP: - case SB_PAGEDOWN: - EDIT_EM_Scroll(wnd, es, action); - return 0; - case SB_TOP: - dy = -es->y_offset; - break; - case SB_BOTTOM: - dy = es->line_count - 1 - es->y_offset; - break; - case SB_THUMBTRACK: - es->flags |= EF_VSCROLL_TRACK; - dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset; - break; - case SB_THUMBPOSITION: - es->flags &= ~EF_VSCROLL_TRACK; - if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset)) - EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); - break; - case SB_ENDSCROLL: - break; - - /* - * FIXME : the next two are undocumented ! - * Are we doing the right thing ? - * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, - * although it's also a regular control message. - */ - case EM_GETTHUMB: - ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0; - break; - case EM_LINESCROLL: - dy = pos; - break; - - default: - DPRINT( "undocumented (hacked) WM_VSCROLL parameter, please report\n"); - return 0; - } - if (dy) - EDIT_EM_LineScroll(wnd, es, 0, dy); - return ret; -} - - -/********************************************************************* - * - * WM_VSCROLL - * - */ -static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar) -{ - INT dy; - - if (!(es->style & ES_MULTILINE)) - return 0; - - if (!(es->style & ES_AUTOVSCROLL)) - return 0; - - if (!(es->style & WS_VSCROLL)) - return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar); - - dy = 0; - switch (action) { - case SB_LINEUP: - case SB_LINEDOWN: - case SB_PAGEUP: - case SB_PAGEDOWN: - EDIT_EM_Scroll(wnd, es, action); - return 0; - - case SB_TOP: - dy = -es->y_offset; - break; - case SB_BOTTOM: - dy = es->line_count - 1 - es->y_offset; - break; - case SB_THUMBTRACK: - es->flags |= EF_VSCROLL_TRACK; - dy = pos - es->y_offset; - break; - case SB_THUMBPOSITION: - es->flags &= ~EF_VSCROLL_TRACK; - if (!(dy = pos - es->y_offset)) { - SetScrollPos(wnd->hwndSelf, SB_VERT, pos, TRUE); - EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); - } - break; - case SB_ENDSCROLL: - break; - - default: - DPRINT( "undocumented WM_VSCROLL action %d, please report\n", - action); - return 0; - } - if (dy) - EDIT_EM_LineScroll(wnd, es, 0, dy); - return 0; -} - -// temporary hack - -WINBOOL -STDCALL -OpenClipboard( - HWND hWndNewOwner) { return 0; } - - -WINBOOL -STDCALL -CloseClipboard( - VOID) { return 0; } - - -HWND -STDCALL -GetClipboardOwner( - VOID) { return 0; } - - -HWND -STDCALL -SetClipboardViewer( - HWND hWndNewViewer) { return 0; } - - -HWND -STDCALL -GetClipboardViewer( - VOID) { return 0; } - - -WINBOOL -STDCALL -ChangeClipboardChain( - HWND hWndRemove, - HWND hWndNewNext) { return 0; } - - -HANDLE -STDCALL -SetClipboardData( - UINT uFormat, - HANDLE hMem) { return 0; } - - -HANDLE -STDCALL -GetClipboardData( - UINT uFormat) { return 0; } - - - -int -STDCALL -CountClipboardFormats( - VOID) { return 0; } - - -UINT -STDCALL -EnumClipboardFormats( - UINT format) { return 0; } - - -WINBOOL -STDCALL -EmptyClipboard( - VOID) { return 0; } - - -WINBOOL -STDCALL -IsClipboardFormatAvailable( - UINT format) { return 0; } - - -int -STDCALL -GetPriorityClipboardFormat( - UINT *paFormatPriorityList, - int cFormats) { return 0; } - - -HWND -STDCALL -GetOpenClipboardWindow( - VOID) { return 0; } - - -UINT -STDCALL -RegisterClipboardFormatA( - LPCSTR lpszFormat) -{ - return 0; -} - -UINT -STDCALL -RegisterClipboardFormatW( - LPCWSTR lpszFormat) -{ - return 0; -} - - - diff --git a/reactos/lib/user32/controls/icontitle.c b/reactos/lib/user32/controls/icontitle.c deleted file mode 100644 index 6c3745205c3..00000000000 --- a/reactos/lib/user32/controls/icontitle.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Icontitle window class. - * - * Copyright 1997 Alex Korobka - */ - -#include -#include -#include -#include -#include -#include - -#define WM_ISACTIVEICON 0x0035 - -static LPCSTR emptyTitleText = "<...>"; - - WINBOOL bMultiLineTitle; - HFONT hIconTitleFont; - -/*********************************************************************** - * ICONTITLE_Init - */ -WINBOOL ICONTITLE_Init(void) -{ - LOGFONT logFont; - - SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 ); - SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0, &bMultiLineTitle, 0 ); - hIconTitleFont = CreateFontIndirectA( &logFont ); - return (hIconTitleFont) ? TRUE : FALSE; -} - -/*********************************************************************** - * ICONTITLE_Create - */ -HWND ICONTITLE_Create( WND* wnd ) -{ - WND* wndPtr; - HWND hWnd; - - - - if( wnd->dwStyle & WS_CHILD ) { - - hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_NAME_A, NULL, - WS_CHILD | WS_CLIPSIBLINGS, 0, 0, 1, 1, - wnd->parent->hwndSelf, 0, wnd->hInstance, NULL ); - } - else { - - hWnd = CreateWindowExA( 0, ICONTITLE_CLASS_NAME_A, NULL, - WS_CLIPSIBLINGS, 0, 0, 1, 1, - wnd->hwndSelf, 0, wnd->hInstance, NULL ); - - } - wndPtr = WIN_FindWndPtr( hWnd ); - if( wndPtr ) - { - wndPtr->owner = wnd; /* MDI depends on this */ - wndPtr->dwStyle &= ~(WS_CAPTION | WS_BORDER); - if( wnd->dwStyle & WS_DISABLED ) wndPtr->dwStyle |= WS_DISABLED; - return hWnd; - } - return 0; -} - -/*********************************************************************** - * ICONTITLE_GetTitlePos - */ -WINBOOL ICONTITLE_GetTitlePos( WND* wnd, LPRECT lpRect ) -{ - LPSTR str; - int length = lstrlenA( wnd->owner->text ); - - if( length ) - { - str = HeapAlloc( GetProcessHeap(), 0, length + 1 ); - lstrcpyA( str, wnd->owner->text ); - while( str[length - 1] == ' ' ) /* remove trailing spaces */ - { - str[--length] = '\0'; - if( !length ) - { - HeapFree( GetProcessHeap(), 0, str ); - break; - } - } - } - if( !length ) - { - str = (LPSTR)emptyTitleText; - length = lstrlenA( str ); - } - - if( str ) - { - HDC hDC = GetDC( wnd->hwndSelf ); - if( hDC ) - { - HFONT hPrevFont = SelectObject( hDC, hIconTitleFont ); - - SetRect( lpRect, 0, 0, sysMetrics[SM_CXICONSPACING] - - SYSMETRICS_CXBORDER * 2, SYSMETRICS_CYBORDER * 2 ); - - DrawTextA( hDC, str, length, lpRect, DT_CALCRECT | - DT_CENTER | DT_NOPREFIX | DT_WORDBREAK | - (( bMultiLineTitle ) ? 0 : DT_SINGLELINE) ); - - SelectObject( hDC, hPrevFont ); - ReleaseDC( wnd->hwndSelf, hDC ); - - lpRect->right += 4 * SYSMETRICS_CXBORDER - lpRect->left; - lpRect->left = wnd->owner->rectWindow.left + SYSMETRICS_CXICON / 2 - - (lpRect->right - lpRect->left) / 2; - lpRect->bottom -= lpRect->top; - lpRect->top = wnd->owner->rectWindow.top + SYSMETRICS_CYICON; - } - if( str != emptyTitleText ) HeapFree( GetProcessHeap(), 0, str ); - return ( hDC ) ? TRUE : FALSE; - } - return FALSE; -} - -/*********************************************************************** - * ICONTITLE_Paint - */ -WINBOOL ICONTITLE_Paint( WND* wnd, HDC hDC, WINBOOL bActive ) -{ - HFONT hPrevFont; - HBRUSH hBrush = 0; - COLORREF textColor = 0; - - if( bActive ) - { - hBrush = GetSysColorBrush(COLOR_ACTIVECAPTION); - textColor = GetSysColor(COLOR_CAPTIONTEXT); - } - else - { - if( wnd->dwStyle & WS_CHILD ) - { - hBrush = wnd->parent->class->hbrBackground; - if( hBrush ) - { - INT level; - LOGBRUSH logBrush; - GetObjectA( hBrush, sizeof(logBrush), &logBrush ); - level = GetRValue(logBrush.lbColor) + - GetGValue(logBrush.lbColor) + - GetBValue(logBrush.lbColor); - if( level < (0x7F * 3) ) - textColor = RGB( 0xFF, 0xFF, 0xFF ); - } - else - hBrush = GetStockObject( WHITE_BRUSH ); - } - else - { - hBrush = GetStockObject( BLACK_BRUSH ); - textColor = RGB( 0xFF, 0xFF, 0xFF ); - } - } - - FillWindow( wnd->parent->hwndSelf, wnd->hwndSelf, hDC, hBrush ); - - hPrevFont = SelectObject( hDC, hIconTitleFont ); - if( hPrevFont ) - { - RECT rect; - INT length; - char buffer[80]; - - rect.left = rect.top = 0; - rect.right = wnd->rectWindow.right - wnd->rectWindow.left; - rect.bottom = wnd->rectWindow.bottom - wnd->rectWindow.top; - - length = GetWindowTextA( wnd->owner->hwndSelf, buffer, 80 ); - SetTextColor( hDC, textColor ); - SetBkMode( hDC, TRANSPARENT ); - - DrawTextA( hDC, buffer, length, &rect, DT_CENTER | DT_NOPREFIX | - DT_WORDBREAK | ((bMultiLineTitle) ? 0 : DT_SINGLELINE) ); - - SelectObject( hDC, hPrevFont ); - } - return ( hPrevFont ) ? TRUE : FALSE; -} - -/*********************************************************************** - * IconTitleWndProc - */ -LRESULT WINAPI IconTitleWndProc( HWND hWnd, UINT msg, - WPARAM wParam, LPARAM lParam ) -{ - WND *wnd = WIN_FindWndPtr( hWnd ); - - switch( msg ) - { - case WM_NCHITTEST: - return HTCAPTION; - - case WM_NCMOUSEMOVE: - case WM_NCLBUTTONDBLCLK: - return SendMessageA( wnd->owner->hwndSelf, msg, wParam, lParam ); - - case WM_ACTIVATE: - if( wParam ) SetActiveWindow( wnd->owner->hwndSelf ); - /* fall through */ - - case WM_CLOSE: - return 0; - - case WM_SHOWWINDOW: - if( wnd && wParam ) - { - RECT titleRect; - - ICONTITLE_GetTitlePos( wnd, &titleRect ); - if( wnd->owner->next != wnd ) /* keep icon title behind the owner */ - SetWindowPos( hWnd, wnd->owner->hwndSelf, - titleRect.left, titleRect.top, - titleRect.right, titleRect.bottom, SWP_NOACTIVATE ); - else - SetWindowPos( hWnd, 0, titleRect.left, titleRect.top, - titleRect.right, titleRect.bottom, - SWP_NOACTIVATE | SWP_NOZORDER ); - } - return 0; - - case WM_ERASEBKGND: - if( wnd ) - { - WND* iconWnd = wnd->owner; - - if( iconWnd->dwStyle & WS_CHILD ) - lParam = SendMessageA( iconWnd->hwndSelf, WM_ISACTIVEICON, 0, 0 ); - else - lParam = (iconWnd->hwndSelf == GetActiveWindow()); - - if( ICONTITLE_Paint( wnd, (HDC)wParam, (WINBOOL)lParam ) ) - ValidateRect( hWnd, NULL ); - return 1; - } - } - - return DefWindowProcA( hWnd, msg, wParam, lParam ); -} - - diff --git a/reactos/lib/user32/controls/listbox.c b/reactos/lib/user32/controls/listbox.c deleted file mode 100644 index ba265053330..00000000000 --- a/reactos/lib/user32/controls/listbox.c +++ /dev/null @@ -1,2559 +0,0 @@ -/* - * Listbox controls - * - * Copyright 1996 Alexandre Julliard - */ - -#include -#define MIN min -#define MAX max - -#include -#include -#include -#include -#include -#include -#include - -#define MAX_DOS_DRIVES 26 - -#define abs(x) ((x) < 0 ? -(x) : (x)) - -#define WM_LBTRACKPOINT 0x0131 -#define WS_EX_DRAGDETECT 0x00000002L - - /* D&D messages */ -#define WM_DROPOBJECT 0x022A -#define WM_QUERYDROPOBJECT 0x022B -#define WM_BEGINDRAG 0x022C -#define WM_DRAGLOOP 0x022D -#define WM_DRAGSELECT 0x022E -#define WM_DRAGMOVE 0x022F - - -/* Unimplemented yet: - * - LBS_NOSEL - * - LBS_USETABSTOPS - * - Unicode - * - Locale handling - */ - -/* Items array granularity */ -#define LB_ARRAY_GRANULARITY 16 - -/* Scrolling timeout in ms */ -#define LB_SCROLL_TIMEOUT 50 - -/* Listbox system timer id */ -#define LB_TIMER_ID 2 - -/* Item structure */ -typedef struct -{ - LPSTR str; /* Item text */ - BOOL selected; /* Is item selected? */ - UINT height; /* Item height (only for OWNERDRAWVARIABLE) */ - DWORD data; /* User data */ -} LB_ITEMDATA; - -/* Listbox structure */ -typedef struct -{ - HANDLE heap; /* Heap for this listbox */ - HWND owner; /* Owner window to send notifications to */ - UINT style; /* Window style */ - INT width; /* Window width */ - INT height; /* Window height */ - LB_ITEMDATA *items; /* Array of items */ - INT nb_items; /* Number of items */ - INT top_item; /* Top visible item */ - INT selected_item; /* Selected item */ - INT focus_item; /* Item that has the focus */ - INT anchor_item; /* Anchor item for extended selection */ - INT item_height; /* Default item height */ - INT page_size; /* Items per listbox page */ - INT column_width; /* Column width for multi-column listboxes */ - INT horz_extent; /* Horizontal extent (0 if no hscroll) */ - INT horz_pos; /* Horizontal position */ - INT nb_tabs; /* Number of tabs in array */ - INT *tabs; /* Array of tabs */ - BOOL caret_on; /* Is caret on? */ - HFONT font; /* Current font */ - LCID locale; /* Current locale for string comparisons */ - LPHEADCOMBO lphc; /* ComboLBox */ -} LB_DESCR; - - -#define IS_OWNERDRAW(descr) \ - ((descr)->style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) - -#define HAS_STRINGS(descr) \ - (!IS_OWNERDRAW(descr) || ((descr)->style & LBS_HASSTRINGS)) - -#define SEND_NOTIFICATION(wnd,descr,code) \ - (SendMessageA( (descr)->owner, WM_COMMAND, \ - MAKEWPARAM((((descr)->lphc)?ID_CB_LISTBOX:(wnd)->wIDmenu), (code) ), (LPARAM)(wnd)->hwndSelf )) - -/* Current timer status */ -typedef enum -{ - LB_TIMER_NONE, - LB_TIMER_UP, - LB_TIMER_LEFT, - LB_TIMER_DOWN, - LB_TIMER_RIGHT -} TIMER_DIRECTION; - -static TIMER_DIRECTION LISTBOX_Timer = LB_TIMER_NONE; - - -/*********************************************************************** - * LISTBOX_DPRINT - */ -void LISTBOX_DPRINT( WND *wnd ) -{ - INT i; - LB_ITEMDATA *item; - LB_DESCR *descr = *(LB_DESCR **)wnd->wExtra; - - DPRINT( "Listbox:\n" ); - DPRINT( "hwnd=%04x descr=%08x heap=%08x items=%d top=%d\n", - wnd->hwndSelf, (UINT)descr, descr->heap, descr->nb_items, - descr->top_item ); - for (i = 0, item = descr->items; i < descr->nb_items; i++, item++) - { - DPRINT( "%4d: %-40s %d %08lx %3d\n", - i, item->str, item->selected, item->data, item->height ); - } -} - - -/*********************************************************************** - * LISTBOX_GetCurrentPageSize - * - * Return the current page size - */ -static INT LISTBOX_GetCurrentPageSize( WND *wnd, LB_DESCR *descr ) -{ - INT i, height; - if (!(descr->style & LBS_OWNERDRAWVARIABLE)) return descr->page_size; - for (i = descr->top_item, height = 0; i < descr->nb_items; i++) - { - if ((height += descr->items[i].height) > descr->height) break; - } - if (i == descr->top_item) return 1; - else return i - descr->top_item; -} - - -/*********************************************************************** - * LISTBOX_GetMaxTopIndex - * - * Return the maximum possible index for the top of the listbox. - */ -static INT LISTBOX_GetMaxTopIndex( WND *wnd, LB_DESCR *descr ) -{ - INT max, page; - - if (descr->style & LBS_OWNERDRAWVARIABLE) - { - page = descr->height; - for (max = descr->nb_items - 1; max >= 0; max--) - if ((page -= descr->items[max].height) < 0) break; - if (max < descr->nb_items - 1) max++; - } - else if (descr->style & LBS_MULTICOLUMN) - { - if ((page = descr->width / descr->column_width) < 1) page = 1; - max = (descr->nb_items + descr->page_size - 1) / descr->page_size; - max = (max - page) * descr->page_size; - } - else - { - max = descr->nb_items - descr->page_size; - } - if (max < 0) max = 0; - return max; -} - - -/*********************************************************************** - * LISTBOX_UpdateScroll - * - * Update the scrollbars. Should be called whenever the content - * of the listbox changes. - */ -static void LISTBOX_UpdateScroll( WND *wnd, LB_DESCR *descr ) -{ - SCROLLINFO info; - - if (!(descr->style & WS_VSCROLL)) return; - /* It is important that we check descr->style, and not wnd->dwStyle, - for WS_VSCROLL, as the former is exactly the one passed in - argument to CreateWindow. - In Windows (and from now on in Wine :) a listbox created - with such a style (no WS_SCROLL) does not update - the scrollbar with listbox-related data, thus letting - the programmer use it for his/her own purposes. */ - - if (descr->style & LBS_NOREDRAW) return; - info.cbSize = sizeof(info); - - if (descr->style & LBS_MULTICOLUMN) - { - info.nMin = 0; - info.nMax = (descr->nb_items - 1) / descr->page_size; - info.nPos = descr->top_item / descr->page_size; - info.nPage = descr->width / descr->column_width; - if (info.nPage < 1) info.nPage = 1; - info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; - if (descr->style & LBS_DISABLENOSCROLL) - info.fMask |= SIF_DISABLENOSCROLL; - SetScrollInfo( wnd->hwndSelf, SB_HORZ, &info, TRUE ); - info.nMax = 0; - info.fMask = SIF_RANGE; - SetScrollInfo( wnd->hwndSelf, SB_VERT, &info, TRUE ); - } - else - { - info.nMin = 0; - info.nMax = descr->nb_items - 1; - info.nPos = descr->top_item; - info.nPage = LISTBOX_GetCurrentPageSize( wnd, descr ); - info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; - if (descr->style & LBS_DISABLENOSCROLL) - info.fMask |= SIF_DISABLENOSCROLL; - SetScrollInfo( wnd->hwndSelf, SB_VERT, &info, TRUE ); - - if (descr->horz_extent) - { - info.nMin = 0; - info.nMax = descr->horz_extent - 1; - info.nPos = descr->horz_pos; - info.nPage = descr->width; - info.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; - if (descr->style & LBS_DISABLENOSCROLL) - info.fMask |= SIF_DISABLENOSCROLL; - SetScrollInfo( wnd->hwndSelf, SB_HORZ, &info, TRUE ); - } - } -} - - -/*********************************************************************** - * LISTBOX_SetTopItem - * - * Set the top item of the listbox, scrolling up or down if necessary. - */ -static LRESULT LISTBOX_SetTopItem( WND *wnd, LB_DESCR *descr, INT index, - BOOL scroll ) -{ - INT max = LISTBOX_GetMaxTopIndex( wnd, descr ); - if (index > max) index = max; - if (index < 0) index = 0; - if (descr->style & LBS_MULTICOLUMN) index -= index % descr->page_size; - if (descr->top_item == index) return LB_OKAY; - if (descr->style & LBS_MULTICOLUMN) - { - INT diff = (descr->top_item - index) / descr->page_size * descr->column_width; - if (scroll && (abs(diff) < descr->width)) - ScrollWindowEx( wnd->hwndSelf, diff, 0, NULL, NULL, 0, NULL, - SW_INVALIDATE | SW_ERASE ); - else - scroll = FALSE; - } - else if (scroll) - { - INT diff; - if (descr->style & LBS_OWNERDRAWVARIABLE) - { - INT i; - diff = 0; - if (index > descr->top_item) - { - for (i = index - 1; i >= descr->top_item; i--) - diff -= descr->items[i].height; - } - else - { - for (i = index; i < descr->top_item; i++) - diff += descr->items[i].height; - } - } - else - diff = (descr->top_item - index) * descr->item_height; - - if (abs(diff) < descr->height) - ScrollWindowEx( wnd->hwndSelf, 0, diff, NULL, NULL, 0, NULL, - SW_INVALIDATE | SW_ERASE ); - else - scroll = FALSE; - } - if (!scroll) InvalidateRect( wnd->hwndSelf, NULL, TRUE ); - descr->top_item = index; - LISTBOX_UpdateScroll( wnd, descr ); - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_UpdatePage - * - * Update the page size. Should be called when the size of - * the client area or the item height changes. - */ -static void LISTBOX_UpdatePage( WND *wnd, LB_DESCR *descr ) -{ - INT page_size; - - if ((page_size = descr->height / descr->item_height) < 1) page_size = 1; - if (page_size == descr->page_size) return; - descr->page_size = page_size; - if (descr->style & LBS_MULTICOLUMN) - InvalidateRect( wnd->hwndSelf, NULL, TRUE ); - LISTBOX_SetTopItem( wnd, descr, descr->top_item, FALSE ); -} - - -/*********************************************************************** - * LISTBOX_UpdateSize - * - * Update the size of the listbox. Should be called when the size of - * the client area changes. - */ -static void LISTBOX_UpdateSize( WND *wnd, LB_DESCR *descr ) -{ - RECT rect; - - GetClientRect( wnd->hwndSelf, &rect ); - descr->width = rect.right - rect.left; - descr->height = rect.bottom - rect.top; - if (!(descr->style & LBS_NOINTEGRALHEIGHT) && !IS_OWNERDRAW(descr)) - { - if ((descr->height > descr->item_height) && - (descr->height % descr->item_height)) - { - DPRINT( "[%04x]: changing height %d -> %d\n", - wnd->hwndSelf, descr->height, - descr->height - descr->height%descr->item_height ); - SetWindowPos( wnd->hwndSelf, 0, 0, 0, - wnd->rectWindow.right - wnd->rectWindow.left, - wnd->rectWindow.bottom - wnd->rectWindow.top - - (descr->height % descr->item_height), - SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE ); - return; - } - } - DPRINT( "[%04x]: new size = %d,%d\n", - wnd->hwndSelf, descr->width, descr->height ); - LISTBOX_UpdatePage( wnd, descr ); - LISTBOX_UpdateScroll( wnd, descr ); -} - - -/*********************************************************************** - * LISTBOX_GetItemRect - * - * Get the rectangle enclosing an item, in listbox client coordinates. - * Return 1 if the rectangle is (partially) visible, 0 if hidden, -1 on error. - */ -static LRESULT LISTBOX_GetItemRect( WND *wnd, LB_DESCR *descr, INT index, - RECT *rect ) -{ - /* Index <= 0 is legal even on empty listboxes */ - if (index && (index >= descr->nb_items)) return -1; - SetRect( rect, 0, 0, descr->width, descr->height ); - if (descr->style & LBS_MULTICOLUMN) - { - INT col = (index / descr->page_size) - - (descr->top_item / descr->page_size); - rect->left += col * descr->column_width; - rect->right = rect->left + descr->column_width; - rect->top += (index % descr->page_size) * descr->item_height; - rect->bottom = rect->top + descr->item_height; - } - else if (descr->style & LBS_OWNERDRAWVARIABLE) - { - INT i; - rect->right += descr->horz_pos; - if ((index >= 0) && (index < descr->nb_items)) - { - if (index < descr->top_item) - { - for (i = descr->top_item-1; i >= index; i--) - rect->top -= descr->items[i].height; - } - else - { - for (i = descr->top_item; i < index; i++) - rect->top += descr->items[i].height; - } - rect->bottom = rect->top + descr->items[index].height; - - } - } - else - { - rect->top += (index - descr->top_item) * descr->item_height; - rect->bottom = rect->top + descr->item_height; - rect->right += descr->horz_pos; - } - - return ((rect->left < descr->width) && (rect->right > 0) && - (rect->top < descr->height) && (rect->bottom > 0)); -} - - -/*********************************************************************** - * LISTBOX_GetItemFromPoint - * - * Return the item nearest from point (x,y) (in client coordinates). - */ -static INT LISTBOX_GetItemFromPoint( WND *wnd, LB_DESCR *descr, - INT x, INT y ) -{ - INT index = descr->top_item; - - if (!descr->nb_items) return -1; /* No items */ - if (descr->style & LBS_OWNERDRAWVARIABLE) - { - INT pos = 0; - if (y >= 0) - { - while (index < descr->nb_items) - { - if ((pos += descr->items[index].height) > y) break; - index++; - } - } - else - { - while (index > 0) - { - index--; - if ((pos -= descr->items[index].height) <= y) break; - } - } - } - else if (descr->style & LBS_MULTICOLUMN) - { - if (y >= descr->item_height * descr->page_size) return -1; - if (y >= 0) index += y / descr->item_height; - if (x >= 0) index += (x / descr->column_width) * descr->page_size; - else index -= (((x + 1) / descr->column_width) - 1) * descr->page_size; - } - else - { - index += (y / descr->item_height); - } - if (index < 0) return 0; - if (index >= descr->nb_items) return -1; - return index; -} - - -/*********************************************************************** - * LISTBOX_PaintItem - * - * Paint an item. - */ -static void LISTBOX_PaintItem( WND *wnd, LB_DESCR *descr, HDC hdc, - const RECT *rect, INT index, UINT action ) -{ - LB_ITEMDATA *item = NULL; - if (index < descr->nb_items) item = &descr->items[index]; - - if (IS_OWNERDRAW(descr)) - { - DRAWITEMSTRUCT dis; - UINT id = (descr->lphc) ? ID_CB_LISTBOX : wnd->wIDmenu; - - dis.CtlType = ODT_LISTBOX; - dis.CtlID = id; - dis.hwndItem = wnd->hwndSelf; - dis.itemAction = action; - dis.hDC = hdc; - dis.itemID = index; - dis.itemState = 0; - if (item && item->selected) dis.itemState |= ODS_SELECTED; - if ((descr->focus_item == index) && - (descr->caret_on) && - (GetFocus() == wnd->hwndSelf)) dis.itemState |= ODS_FOCUS; - if (wnd->dwStyle & WS_DISABLED) dis.itemState |= ODS_DISABLED; - dis.itemData = item ? item->data : 0; - dis.rcItem = *rect; - DPRINT( "[%04x]: drawitem %d (%s) action=%02x " - "state=%02x rect=%d,%d-%d,%d\n", - wnd->hwndSelf, index, item ? item->str : "", action, - dis.itemState, rect->left, rect->top, - rect->right, rect->bottom ); - SendMessageA(descr->owner, WM_DRAWITEM, id, (LPARAM)&dis); - } - else - { - COLORREF oldText = 0, oldBk = 0; - - if (action == ODA_FOCUS) - { - DrawFocusRect( hdc, rect ); - return; - } - if (item && item->selected) - { - oldBk = SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) ); - oldText = SetTextColor( hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); - } - - DPRINT( "[%04x]: painting %d (%s) action=%02x " - "rect=%d,%d-%d,%d\n", - wnd->hwndSelf, index, item ? item->str : "", action, - rect->left, rect->top, rect->right, rect->bottom ); - if (!item) - ExtTextOutA( hdc, rect->left + 1, rect->top + 1, - ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL ); - else if (!(descr->style & LBS_USETABSTOPS)) - ExtTextOutA( hdc, rect->left + 1, rect->top + 1, - ETO_OPAQUE | ETO_CLIPPED, rect, item->str, - strlen(item->str), NULL ); - else - { - /* Output empty string to paint background in the full width. */ - ExtTextOutA( hdc, rect->left + 1, rect->top + 1, - ETO_OPAQUE | ETO_CLIPPED, rect, NULL, 0, NULL ); - TabbedTextOutA( hdc, rect->left + 1 , rect->top + 1, - item->str, strlen(item->str), - descr->nb_tabs, descr->tabs, 0); - } - if (item && item->selected) - { - SetBkColor( hdc, oldBk ); - SetTextColor( hdc, oldText ); - } - if ((descr->focus_item == index) && - (descr->caret_on) && - (GetFocus() == wnd->hwndSelf)) DrawFocusRect( hdc, rect ); - } -} - - -/*********************************************************************** - * LISTBOX_SetRedraw - * - * Change the redraw flag. - */ -static void LISTBOX_SetRedraw( WND *wnd, LB_DESCR *descr, BOOL on ) -{ - if (on) - { - if (!(descr->style & LBS_NOREDRAW)) return; - descr->style &= ~LBS_NOREDRAW; - LISTBOX_UpdateScroll( wnd, descr ); - } - else descr->style |= LBS_NOREDRAW; -} - - -/*********************************************************************** - * LISTBOX_RepaintItem - * - * Repaint a single item synchronously. - */ -static void LISTBOX_RepaintItem( WND *wnd, LB_DESCR *descr, INT index, - UINT action ) -{ - HDC hdc; - RECT rect; - HFONT oldFont = 0; - HBRUSH hbrush, oldBrush = 0; - - if (descr->style & LBS_NOREDRAW) return; - if (LISTBOX_GetItemRect( wnd, descr, index, &rect ) != 1) return; - if (!(hdc = GetDCEx( wnd->hwndSelf, 0, DCX_CACHE ))) return; - if (descr->font) oldFont = SelectObject( hdc, descr->font ); - hbrush = (HBRUSH)SendMessageA( descr->owner, WM_CTLCOLORLISTBOX, - (WPARAM)hdc, (LPARAM)wnd->hwndSelf ); - if (hbrush) oldBrush = SelectObject( hdc, hbrush ); - if (wnd->dwStyle & WS_DISABLED) - SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) ); - SetWindowOrgEx( hdc, descr->horz_pos, 0, NULL ); - LISTBOX_PaintItem( wnd, descr, hdc, &rect, index, action ); - if (oldFont) SelectObject( hdc, oldFont ); - if (oldBrush) SelectObject( hdc, oldBrush ); - ReleaseDC( wnd->hwndSelf, hdc ); -} - - -/*********************************************************************** - * LISTBOX_InitStorage - */ -static LRESULT LISTBOX_InitStorage( WND *wnd, LB_DESCR *descr, INT nb_items, - DWORD bytes ) -{ - LB_ITEMDATA *item; - - nb_items += LB_ARRAY_GRANULARITY - 1; - nb_items -= (nb_items % LB_ARRAY_GRANULARITY); - if (descr->items) - nb_items += HeapSize( descr->heap, 0, descr->items ) / sizeof(*item); - if (!(item = HeapReAlloc( descr->heap, 0, descr->items, - nb_items * sizeof(LB_ITEMDATA) ))) - { - SEND_NOTIFICATION( wnd, descr, LBN_ERRSPACE ); - return LB_ERRSPACE; - } - descr->items = item; - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_SetTabStops - */ -static BOOL LISTBOX_SetTabStops( WND *wnd, LB_DESCR *descr, INT count, - LPINT tabs, BOOL short_ints ) -{ - if (!(descr->style & LBS_USETABSTOPS)) return TRUE; - if (descr->tabs) HeapFree( descr->heap, 0, descr->tabs ); - if (!(descr->nb_tabs = count)) - { - descr->tabs = NULL; - return TRUE; - } - /* FIXME: count = 1 */ - if (!(descr->tabs = (INT *)HeapAlloc( descr->heap, 0, - descr->nb_tabs * sizeof(INT) ))) - return FALSE; - if (short_ints) - { - INT i; - INT * p = (INT *)tabs; -// dbg_decl_str(listbox, 256); - - for (i = 0; i < descr->nb_tabs; i++) { - descr->tabs[i] = *p++<<1; /* FIXME */ - // if(TRACE_ON(listbox)) - // dsprintf(listbox, "%hd ", descr->tabs[i]); - } - DPRINT( "[%04x]: settabstops %s\n", - wnd->hwndSelf, dbg_str(listbox)); - } - else memcpy( descr->tabs, tabs, descr->nb_tabs * sizeof(INT) ); - /* FIXME: repaint the window? */ - return TRUE; -} - - -/*********************************************************************** - * LISTBOX_GetText - */ -static LRESULT LISTBOX_GetText( WND *wnd, LB_DESCR *descr, INT index, - LPSTR buffer ) -{ - if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; - if (HAS_STRINGS(descr)) - { - if (!buffer) - return strlen(descr->items[index].str); - lstrcpyA( buffer, descr->items[index].str ); - return strlen(buffer); - } else { - if (buffer) - *((LPDWORD)buffer)=*(LPDWORD)(&descr->items[index].data); - return sizeof(DWORD); - } -} - - -/*********************************************************************** - * LISTBOX_FindStringPos - * - * Find the nearest string located before a given string in sort order. - * If 'exact' is TRUE, return an error if we don't get an exact match. - */ -static INT LISTBOX_FindStringPos( WND *wnd, LB_DESCR *descr, LPCSTR str, - BOOL exact ) -{ - INT index, min, max, res = -1; - - if (!(descr->style & LBS_SORT)) return -1; /* Add it at the end */ - min = 0; - max = descr->nb_items; - while (min != max) - { - index = (min + max) / 2; - if (HAS_STRINGS(descr)) - res = lstrcmpiA( descr->items[index].str, str ); - else - { - COMPAREITEMSTRUCT cis; - UINT id = (descr->lphc) ? ID_CB_LISTBOX : wnd->wIDmenu; - - cis.CtlType = ODT_LISTBOX; - cis.CtlID = id; - cis.hwndItem = wnd->hwndSelf; - cis.itemID1 = index; - cis.itemData1 = descr->items[index].data; - cis.itemID2 = -1; - cis.itemData2 = (DWORD)str; - //cis.dwLocaleId = descr->locale; - res = SendMessageA( descr->owner, WM_COMPAREITEM, - id, (LPARAM)&cis ); - } - if (!res) return index; - if (res > 0) max = index; - else min = index + 1; - } - return exact ? -1 : max; -} - - -/*********************************************************************** - * LISTBOX_FindFileStrPos - * - * Find the nearest string located before a given string in directory - * sort order (i.e. first files, then directories, then drives). - */ -static INT LISTBOX_FindFileStrPos( WND *wnd, LB_DESCR *descr, LPCSTR str ) -{ - INT min, max, res = -1; - - if (!HAS_STRINGS(descr)) - return LISTBOX_FindStringPos( wnd, descr, str, FALSE ); - min = 0; - max = descr->nb_items; - while (min != max) - { - INT index = (min + max) / 2; - const char *p = descr->items[index].str; - if (*p == '[') /* drive or directory */ - { - if (*str != '[') res = -1; - else if (p[1] == '-') /* drive */ - { - if (str[1] == '-') res = str[2] - p[2]; - else res = -1; - } - else /* directory */ - { - if (str[1] == '-') res = 1; - else res = lstrcmpiA( str, p ); - } - } - else /* filename */ - { - if (*str == '[') res = 1; - else res = lstrcmpiA( str, p ); - } - if (!res) return index; - if (res < 0) max = index; - else min = index + 1; - } - return max; -} - - -/*********************************************************************** - * LISTBOX_FindString - * - * Find the item beginning with a given string. - */ -static INT LISTBOX_FindString( WND *wnd, LB_DESCR *descr, INT start, - LPCSTR str, BOOL exact ) -{ - INT i; - LB_ITEMDATA *item; - - if (start >= descr->nb_items) start = -1; - item = descr->items + start + 1; - if (HAS_STRINGS(descr)) - { - if (!str) return LB_ERR; - if (exact) - { - for (i = start + 1; i < descr->nb_items; i++, item++) - if (!lstrcmpiA( str, item->str )) return i; - for (i = 0, item = descr->items; i <= start; i++, item++) - if (!lstrcmpiA( str, item->str )) return i; - } - else - { - /* Special case for drives and directories: ignore prefix */ -#define CHECK_DRIVE(item) \ - if ((item)->str[0] == '[') \ - { \ - if (!lstrcmpiA( str, (item)->str+1 )) return i; \ - if (((item)->str[1] == '-') && !lstrcmpiA(str,(item)->str+2)) \ - return i; \ - } - - INT len = lstrlenA(str); - for (i = start + 1; i < descr->nb_items; i++, item++) - { - if (!lstrcmpiA( str, item->str )) return i; - CHECK_DRIVE(item); - } - for (i = 0, item = descr->items; i <= start; i++, item++) - { - if (!lstrcmpiA( str, item->str )) return i; - CHECK_DRIVE(item); - } -#undef CHECK_DRIVE - } - } - else - { - if (exact && (descr->style & LBS_SORT)) - /* If sorted, use a WM_COMPAREITEM binary search */ - return LISTBOX_FindStringPos( wnd, descr, str, TRUE ); - - /* Otherwise use a linear search */ - for (i = start + 1; i < descr->nb_items; i++, item++) - if (item->data == (DWORD)str) return i; - for (i = 0, item = descr->items; i <= start; i++, item++) - if (item->data == (DWORD)str) return i; - } - return LB_ERR; -} - - -/*********************************************************************** - * LISTBOX_GetSelCount - */ -static LRESULT LISTBOX_GetSelCount( WND *wnd, LB_DESCR *descr ) -{ - INT i, count; - LB_ITEMDATA *item = descr->items; - - if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; - for (i = count = 0; i < descr->nb_items; i++, item++) - if (item->selected) count++; - return count; -} - - - - -/*********************************************************************** - * LISTBOX_GetSelItems - */ -static LRESULT LISTBOX_GetSelItems( WND *wnd, LB_DESCR *descr, INT max, - LPINT array ) -{ - INT i, count; - LB_ITEMDATA *item = descr->items; - - if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; - for (i = count = 0; (i < descr->nb_items) && (count < max); i++, item++) - if (item->selected) array[count++] = i; - return count; -} - - -/*********************************************************************** - * LISTBOX_Paint - */ -static LRESULT LISTBOX_Paint( WND *wnd, LB_DESCR *descr, HDC hdc ) -{ - INT i, col_pos = descr->page_size - 1; - RECT rect; - HFONT oldFont = 0; - HBRUSH hbrush, oldBrush = 0; - - SetRect( &rect, 0, 0, descr->width, descr->height ); - if (descr->style & LBS_NOREDRAW) return 0; - if (descr->style & LBS_MULTICOLUMN) - rect.right = rect.left + descr->column_width; - else if (descr->horz_pos) - { - SetWindowOrgEx( hdc, descr->horz_pos, 0, NULL ); - rect.right += descr->horz_pos; - } - - if (descr->font) oldFont = SelectObject( hdc, descr->font ); - hbrush = SendMessageA( descr->owner, WM_CTLCOLORLISTBOX, - (WPARAM)hdc, (LPARAM)wnd->hwndSelf ); - if (hbrush) oldBrush = SelectObject( hdc, hbrush ); - if (wnd->dwStyle & WS_DISABLED) - SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) ); - - if (!descr->nb_items && (descr->focus_item != -1) && descr->caret_on && - (GetFocus() == wnd->hwndSelf)) - { - /* Special case for empty listbox: paint focus rect */ - rect.bottom = rect.top + descr->item_height; - LISTBOX_PaintItem( wnd, descr, hdc, &rect, descr->focus_item, - ODA_FOCUS ); - rect.top = rect.bottom; - } - - for (i = descr->top_item; i < descr->nb_items; i++) - { - if (!(descr->style & LBS_OWNERDRAWVARIABLE)) - rect.bottom = rect.top + descr->item_height; - else - rect.bottom = rect.top + descr->items[i].height; - - LISTBOX_PaintItem( wnd, descr, hdc, &rect, i, ODA_DRAWENTIRE ); - rect.top = rect.bottom; - - if ((descr->style & LBS_MULTICOLUMN) && !col_pos) - { - if (!IS_OWNERDRAW(descr)) - { - /* Clear the bottom of the column */ - SetBkColor( hdc, GetSysColor( COLOR_WINDOW ) ); - if (rect.top < descr->height) - { - rect.bottom = descr->height; - ExtTextOutA( hdc, 0, 0, ETO_OPAQUE | ETO_CLIPPED, - &rect, NULL, 0, NULL ); - } - } - - /* Go to the next column */ - rect.left += descr->column_width; - rect.right += descr->column_width; - rect.top = 0; - col_pos = descr->page_size - 1; - } - else - { - col_pos--; - if (rect.top >= descr->height) break; - } - } - - if (!IS_OWNERDRAW(descr)) - { - /* Clear the remainder of the client area */ - SetBkColor( hdc, GetSysColor( COLOR_WINDOW ) ); - if (rect.top < descr->height) - { - rect.bottom = descr->height; - ExtTextOutA( hdc, 0, 0, ETO_OPAQUE | ETO_CLIPPED, - &rect, NULL, 0, NULL ); - } - if (rect.right < descr->width) - { - rect.left = rect.right; - rect.right = descr->width; - rect.top = 0; - rect.bottom = descr->height; - ExtTextOutA( hdc, 0, 0, ETO_OPAQUE | ETO_CLIPPED, - &rect, NULL, 0, NULL ); - } - } - if (oldFont) SelectObject( hdc, oldFont ); - if (oldBrush) SelectObject( hdc, oldBrush ); - return 0; -} - - -/*********************************************************************** - * LISTBOX_InvalidateItems - * - * Invalidate all items from a given item. If the specified item is not - * visible, nothing happens. - */ -static void LISTBOX_InvalidateItems( WND *wnd, LB_DESCR *descr, INT index ) -{ - RECT rect; - - if (LISTBOX_GetItemRect( wnd, descr, index, &rect ) == 1) - { - rect.bottom = descr->height; - InvalidateRect( wnd->hwndSelf, &rect, TRUE ); - if (descr->style & LBS_MULTICOLUMN) - { - /* Repaint the other columns */ - rect.left = rect.right; - rect.right = descr->width; - rect.top = 0; - InvalidateRect( wnd->hwndSelf, &rect, TRUE ); - } - } -} - - -/*********************************************************************** - * LISTBOX_GetItemHeight - */ -static LRESULT LISTBOX_GetItemHeight( WND *wnd, LB_DESCR *descr, INT index ) -{ - if (descr->style & LBS_OWNERDRAWVARIABLE) - { - if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; - return descr->items[index].height; - } - else return descr->item_height; -} - - -/*********************************************************************** - * LISTBOX_SetItemHeight - */ -static LRESULT LISTBOX_SetItemHeight( WND *wnd, LB_DESCR *descr, INT index, - UINT height ) -{ - if (!height) height = 1; - - if (descr->style & LBS_OWNERDRAWVARIABLE) - { - if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; - DPRINT( "[%04x]: item %d height = %d\n", - wnd->hwndSelf, index, height ); - descr->items[index].height = height; - LISTBOX_UpdateScroll( wnd, descr ); - LISTBOX_InvalidateItems( wnd, descr, index ); - } - else if (height != descr->item_height) - { - DPRINT( "[%04x]: new height = %d\n", - wnd->hwndSelf, height ); - descr->item_height = height; - LISTBOX_UpdatePage( wnd, descr ); - LISTBOX_UpdateScroll( wnd, descr ); - InvalidateRect( wnd->hwndSelf, 0, TRUE ); - } - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_SetHorizontalPos - */ -static void LISTBOX_SetHorizontalPos( WND *wnd, LB_DESCR *descr, INT pos ) -{ - INT diff; - - if (pos > descr->horz_extent - descr->width) - pos = descr->horz_extent - descr->width; - if (pos < 0) pos = 0; - if (!(diff = descr->horz_pos - pos)) return; - DPRINT( "[%04x]: new horz pos = %d\n", - wnd->hwndSelf, pos ); - descr->horz_pos = pos; - LISTBOX_UpdateScroll( wnd, descr ); - if (abs(diff) < descr->width) - ScrollWindowEx( wnd->hwndSelf, diff, 0, NULL, NULL, 0, NULL, - SW_INVALIDATE | SW_ERASE ); - else - InvalidateRect( wnd->hwndSelf, NULL, TRUE ); -} - - -/*********************************************************************** - * LISTBOX_SetHorizontalExtent - */ -static LRESULT LISTBOX_SetHorizontalExtent( WND *wnd, LB_DESCR *descr, - UINT extent ) -{ - if (!descr->horz_extent || (descr->style & LBS_MULTICOLUMN)) - return LB_OKAY; - if (extent <= 0) extent = 1; - if (extent == descr->horz_extent) return LB_OKAY; - DPRINT( "[%04x]: new horz extent = %d\n", - wnd->hwndSelf, extent ); - descr->horz_extent = extent; - if (descr->horz_pos > extent - descr->width) - LISTBOX_SetHorizontalPos( wnd, descr, extent - descr->width ); - else - LISTBOX_UpdateScroll( wnd, descr ); - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_SetColumnWidth - */ -static LRESULT LISTBOX_SetColumnWidth( WND *wnd, LB_DESCR *descr, UINT width) -{ - width += 2; /* For left and right margin */ - if (width == descr->column_width) return LB_OKAY; - DPRINT( "[%04x]: new column width = %d\n", - wnd->hwndSelf, width ); - descr->column_width = width; - LISTBOX_UpdatePage( wnd, descr ); - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_SetFont - * - * Returns the item height. - */ -static INT LISTBOX_SetFont( WND *wnd, LB_DESCR *descr, HFONT font ) -{ - HDC hdc; - HFONT oldFont = 0; - TEXTMETRIC tm; - - descr->font = font; - - if (!(hdc = GetDCEx( wnd->hwndSelf, 0, DCX_CACHE ))) - { - DPRINT("unable to get DC.\n" ); - return 16; - } - if (font) oldFont = SelectObject( hdc, font ); - GetTextMetricsA( hdc, &tm ); - if (oldFont) SelectObject( hdc, oldFont ); - ReleaseDC( wnd->hwndSelf, hdc ); - if (!IS_OWNERDRAW(descr)) - LISTBOX_SetItemHeight( wnd, descr, 0, tm.tmHeight ); - return tm.tmHeight ; -} - - -/*********************************************************************** - * LISTBOX_MakeItemVisible - * - * Make sure that a given item is partially or fully visible. - */ -static void LISTBOX_MakeItemVisible( WND *wnd, LB_DESCR *descr, INT index, - BOOL fully ) -{ - INT top; - - if (index <= descr->top_item) top = index; - else if (descr->style & LBS_MULTICOLUMN) - { - INT cols = descr->width; - if (!fully) cols += descr->column_width - 1; - if (cols >= descr->column_width) cols /= descr->column_width; - else cols = 1; - if (index < descr->top_item + (descr->page_size * cols)) return; - top = index - descr->page_size * (cols - 1); - } - else if (descr->style & LBS_OWNERDRAWVARIABLE) - { - INT height = fully ? descr->items[index].height : 1; - for (top = index; top > descr->top_item; top--) - if ((height += descr->items[top-1].height) > descr->height) break; - } - else - { - if (index < descr->top_item + descr->page_size) return; - if (!fully && (index == descr->top_item + descr->page_size) && - (descr->height > (descr->page_size * descr->item_height))) return; - top = index - descr->page_size + 1; - } - LISTBOX_SetTopItem( wnd, descr, top, TRUE ); -} - - -/*********************************************************************** - * LISTBOX_SelectItemRange - * - * Select a range of items. Should only be used on a MULTIPLESEL listbox. - */ -static LRESULT LISTBOX_SelectItemRange( WND *wnd, LB_DESCR *descr, INT first, - INT last, BOOL on ) -{ - INT i; - - /* A few sanity checks */ - - if ((last == -1) && (descr->nb_items == 0)) return LB_OKAY; - if (!(descr->style & LBS_MULTIPLESEL)) return LB_ERR; - if (last == -1) last = descr->nb_items - 1; - if ((first < 0) || (first >= descr->nb_items)) return LB_ERR; - if ((last < 0) || (last >= descr->nb_items)) return LB_ERR; - /* selected_item reflects last selected/unselected item on multiple sel */ - descr->selected_item = last; - - if (on) /* Turn selection on */ - { - for (i = first; i <= last; i++) - { - if (descr->items[i].selected) continue; - descr->items[i].selected = TRUE; - LISTBOX_RepaintItem( wnd, descr, i, ODA_SELECT ); - } - } - else /* Turn selection off */ - { - for (i = first; i <= last; i++) - { - if (!descr->items[i].selected) continue; - descr->items[i].selected = FALSE; - LISTBOX_RepaintItem( wnd, descr, i, ODA_SELECT ); - } - } - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_SetCaretIndex - * - * NOTES - * index must be between 0 and descr->nb_items-1, or LB_ERR is returned. - * - */ -static LRESULT LISTBOX_SetCaretIndex( WND *wnd, LB_DESCR *descr, INT index, - BOOL fully_visible ) -{ - INT oldfocus = descr->focus_item; - - if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; - if (index == oldfocus) return LB_OKAY; - descr->focus_item = index; - if ((oldfocus != -1) && descr->caret_on && (GetFocus() == wnd->hwndSelf)) - LISTBOX_RepaintItem( wnd, descr, oldfocus, ODA_FOCUS ); - - LISTBOX_MakeItemVisible( wnd, descr, index, fully_visible ); - if (descr->caret_on && (GetFocus() == wnd->hwndSelf)) - LISTBOX_RepaintItem( wnd, descr, index, ODA_FOCUS ); - - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_SetSelection - */ -static LRESULT LISTBOX_SetSelection( WND *wnd, LB_DESCR *descr, INT index, - BOOL on, BOOL send_notify ) -{ - if ((index < -1) || (index >= descr->nb_items)) return LB_ERR; - if (descr->style & LBS_MULTIPLESEL) - { - if (index == -1) /* Select all items */ - return LISTBOX_SelectItemRange( wnd, descr, 0, -1, on ); - else /* Only one item */ - return LISTBOX_SelectItemRange( wnd, descr, index, index, on ); - } - else - { - INT oldsel = descr->selected_item; - if (index == oldsel) return LB_OKAY; - if (oldsel != -1) descr->items[oldsel].selected = FALSE; - if (index != -1) descr->items[index].selected = TRUE; - descr->selected_item = index; - if (oldsel != -1) LISTBOX_RepaintItem( wnd, descr, oldsel, ODA_SELECT); - if (index != -1) LISTBOX_RepaintItem( wnd, descr, index, ODA_SELECT ); - if (send_notify) SEND_NOTIFICATION( wnd, descr, - (index != -1) ? LBN_SELCHANGE : LBN_SELCANCEL ); - else - if( descr->lphc ) /* set selection change flag for parent combo */ - descr->lphc->wState |= CBF_SELCHANGE; - } - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_MoveCaret - * - * Change the caret position and extend the selection to the new caret. - */ -static void LISTBOX_MoveCaret( WND *wnd, LB_DESCR *descr, INT index, - BOOL fully_visible ) -{ - LISTBOX_SetCaretIndex( wnd, descr, index, fully_visible ); - if (descr->style & LBS_EXTENDEDSEL) - { - if (descr->anchor_item != -1) - { - INT first = MIN( descr->focus_item, descr->anchor_item ); - INT last = MAX( descr->focus_item, descr->anchor_item ); - if (first > 0) - LISTBOX_SelectItemRange( wnd, descr, 0, first - 1, FALSE ); - LISTBOX_SelectItemRange( wnd, descr, last + 1, -1, FALSE ); - LISTBOX_SelectItemRange( wnd, descr, first, last, TRUE ); - } - } - else if (!(descr->style & LBS_MULTIPLESEL) && (descr->selected_item != -1)) - { - /* Set selection to new caret item */ - LISTBOX_SetSelection( wnd, descr, index, TRUE, FALSE ); - } -} - - -/*********************************************************************** - * LISTBOX_InsertItem - */ -static LRESULT LISTBOX_InsertItem( WND *wnd, LB_DESCR *descr, INT index, - LPSTR str, DWORD data ) -{ - LB_ITEMDATA *item; - INT max_items; - - if (index == -1) index = descr->nb_items; - else if ((index < 0) || (index > descr->nb_items)) return LB_ERR; - if (!descr->items) max_items = 0; - else max_items = HeapSize( descr->heap, 0, descr->items ) / sizeof(*item); - if (descr->nb_items == max_items) - { - /* We need to grow the array */ - max_items += LB_ARRAY_GRANULARITY; - if (!(item = HeapReAlloc( descr->heap, 0, descr->items, - max_items * sizeof(LB_ITEMDATA) ))) - { - SEND_NOTIFICATION( wnd, descr, LBN_ERRSPACE ); - return LB_ERRSPACE; - } - descr->items = item; - } - - /* Insert the item structure */ - - item = &descr->items[index]; - if (index < descr->nb_items) - MoveMemory( item + 1, item, (descr->nb_items - index) * sizeof(LB_ITEMDATA) ); - item->str = str; - item->data = data; - item->height = 0; - item->selected = FALSE; - descr->nb_items++; - - /* Get item height */ - - if (descr->style & LBS_OWNERDRAWVARIABLE) - { - MEASUREITEMSTRUCT mis; - UINT id = (descr->lphc) ? ID_CB_LISTBOX : wnd->wIDmenu; - - mis.CtlType = ODT_LISTBOX; - mis.CtlID = id; - mis.itemID = index; - mis.itemData = descr->items[index].data; - mis.itemHeight = descr->item_height; - SendMessageA( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis ); - item->height = mis.itemHeight ? mis.itemHeight : 1; - DPRINT( "[%04x]: measure item %d (%s) = %d\n", - wnd->hwndSelf, index, str ? str : "", item->height ); - } - - /* Repaint the items */ - - LISTBOX_UpdateScroll( wnd, descr ); - LISTBOX_InvalidateItems( wnd, descr, index ); - - /* Move selection and focused item */ - - if (index <= descr->selected_item) descr->selected_item++; - if (index <= descr->focus_item) - { - descr->focus_item++; - LISTBOX_MoveCaret( wnd, descr, descr->focus_item, FALSE ); - } - - /* If listbox was empty, set focus to the first item */ - - if (descr->nb_items == 1) LISTBOX_SetCaretIndex( wnd, descr, 0, FALSE ); - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_InsertString - */ -static LRESULT LISTBOX_InsertString( WND *wnd, LB_DESCR *descr, INT index, - LPCSTR str ) -{ - LPSTR new_str = NULL; - DWORD data = 0; - LRESULT ret; - - if (HAS_STRINGS(descr)) - { - if (!(new_str = HEAP_strdupA( descr->heap, 0, str ))) - { - SEND_NOTIFICATION( wnd, descr, LBN_ERRSPACE ); - return LB_ERRSPACE; - } - } - else data = (DWORD)str; - - if (index == -1) index = descr->nb_items; - if ((ret = LISTBOX_InsertItem( wnd, descr, index, new_str, data )) != 0) - { - if (new_str) HeapFree( descr->heap, 0, new_str ); - return ret; - } - - DPRINT( "[%04x]: added item %d '%s'\n", - wnd->hwndSelf, index, HAS_STRINGS(descr) ? new_str : "" ); - return index; -} - - -/*********************************************************************** - * LISTBOX_DeleteItem - * - * Delete the content of an item. 'index' must be a valid index. - */ -static void LISTBOX_DeleteItem( WND *wnd, LB_DESCR *descr, INT index ) -{ - /* Note: Win 3.1 only sends DELETEITEM on owner-draw items, - * while Win95 sends it for all items with user data. - * It's probably better to send it too often than not - * often enough, so this is what we do here. - */ - if (IS_OWNERDRAW(descr) || descr->items[index].data) - { - DELETEITEMSTRUCT dis; - UINT id = (descr->lphc) ? ID_CB_LISTBOX : wnd->wIDmenu; - - dis.CtlType = ODT_LISTBOX; - dis.CtlID = id; - dis.itemID = index; - dis.hwndItem = wnd->hwndSelf; - dis.itemData = descr->items[index].data; - SendMessageA( descr->owner, WM_DELETEITEM, id, (LPARAM)&dis ); - } - if (HAS_STRINGS(descr) && descr->items[index].str) - HeapFree( descr->heap, 0, descr->items[index].str ); -} - - -/*********************************************************************** - * LISTBOX_RemoveItem - * - * Remove an item from the listbox and delete its content. - */ -static LRESULT LISTBOX_RemoveItem( WND *wnd, LB_DESCR *descr, INT index ) -{ - LB_ITEMDATA *item; - INT max_items; - - if (index == -1) index = descr->nb_items - 1; - else if ((index < 0) || (index >= descr->nb_items)) return LB_ERR; - LISTBOX_DeleteItem( wnd, descr, index ); - - /* Remove the item */ - - item = &descr->items[index]; - if (index < descr->nb_items-1) - MoveMemory( item, item + 1, - (descr->nb_items - index - 1) * sizeof(LB_ITEMDATA) ); - descr->nb_items--; - if (descr->anchor_item == descr->nb_items) descr->anchor_item--; - - /* Shrink the item array if possible */ - - max_items = HeapSize( descr->heap, 0, descr->items ) / sizeof(LB_ITEMDATA); - if (descr->nb_items < max_items - 2*LB_ARRAY_GRANULARITY) - { - max_items -= LB_ARRAY_GRANULARITY; - item = HeapReAlloc( descr->heap, 0, descr->items, - max_items * sizeof(LB_ITEMDATA) ); - if (item) descr->items = item; - } - - /* Repaint the items */ - - LISTBOX_UpdateScroll( wnd, descr ); - LISTBOX_InvalidateItems( wnd, descr, index ); - - /* Move selection and focused item */ - - if (index <= descr->selected_item) descr->selected_item--; - if (index <= descr->focus_item) - { - descr->focus_item--; - LISTBOX_MoveCaret( wnd, descr, descr->focus_item, FALSE ); - } - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_ResetContent - */ -static void LISTBOX_ResetContent( WND *wnd, LB_DESCR *descr ) -{ - INT i; - - for (i = 0; i < descr->nb_items; i++) LISTBOX_DeleteItem( wnd, descr, i ); - if (descr->items) HeapFree( descr->heap, 0, descr->items ); - descr->nb_items = 0; - descr->top_item = 0; - descr->selected_item = -1; - descr->focus_item = 0; - descr->anchor_item = -1; - descr->items = NULL; - LISTBOX_UpdateScroll( wnd, descr ); - InvalidateRect( wnd->hwndSelf, NULL, TRUE ); -} - - -/*********************************************************************** - * LISTBOX_SetCount - */ -static LRESULT LISTBOX_SetCount( WND *wnd, LB_DESCR *descr, INT count ) -{ - LRESULT ret; - - if (HAS_STRINGS(descr)) return LB_ERR; - /* FIXME: this is far from optimal... */ - if (count > descr->nb_items) - { - while (count > descr->nb_items) - if ((ret = LISTBOX_InsertString( wnd, descr, -1, 0 )) < 0) - return ret; - } - else if (count < descr->nb_items) - { - while (count < descr->nb_items) - if ((ret = LISTBOX_RemoveItem( wnd, descr, -1 )) < 0) - return ret; - } - return LB_OKAY; -} - - -/*********************************************************************** - * LISTBOX_Directory - */ -static LRESULT LISTBOX_Directory( WND *wnd, LB_DESCR *descr, UINT attrib, - LPCSTR filespec, BOOL long_names ) -{ - HANDLE handle; - LRESULT ret = LB_OKAY; - WIN32_FIND_DATA entry; - int pos; - - if ((handle = FindFirstFileA(filespec,&entry)) == INVALID_HANDLE_VALUE) - { - if (GetLastError() != ERROR_NO_MORE_FILES) return LB_ERR; - } - else - { - do - { - char buffer[270]; - if (entry.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - if (!(attrib & DDL_DIRECTORY) || - !strcmp( entry.cAlternateFileName, "." )) continue; - if (long_names) sprintf( buffer, "[%s]", entry.cFileName ); - else sprintf( buffer, "[%s]", entry.cAlternateFileName ); - } - else /* not a directory */ - { -#define ATTRIBS (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | \ - FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE) - - if ((attrib & DDL_EXCLUSIVE) && - ((attrib & ATTRIBS) != (entry.dwFileAttributes & ATTRIBS))) - continue; -#undef ATTRIBS - if (long_names) strcpy( buffer, entry.cFileName ); - else strcpy( buffer, entry.cAlternateFileName ); - } - if (!long_names) CharLowerA( buffer ); - pos = LISTBOX_FindFileStrPos( wnd, descr, buffer ); - if ((ret = LISTBOX_InsertString( wnd, descr, pos, buffer )) < 0) - break; - } while (FindNextFileA( handle, &entry )); - FindClose( handle ); - } - - if ((ret >= 0) && (attrib & DDL_DRIVES)) - { - char buffer[] = "[-a-]"; - int drive; - for (drive = 0; drive < MAX_DOS_DRIVES; drive++, buffer[2]++) - { - //if (!DRIVE_IsValid(drive)) continue; - if ((ret = LISTBOX_InsertString( wnd, descr, -1, buffer )) < 0) - break; - } - } - return ret; -} - - -/*********************************************************************** - * LISTBOX_HandleVScroll - */ -static LRESULT LISTBOX_HandleVScroll( WND *wnd, LB_DESCR *descr, - WPARAM wParam, LPARAM lParam ) -{ - SCROLLINFO info; - - if (descr->style & LBS_MULTICOLUMN) return 0; - switch(LOWORD(wParam)) - { - case SB_LINEUP: - LISTBOX_SetTopItem( wnd, descr, descr->top_item - 1, TRUE ); - break; - case SB_LINEDOWN: - LISTBOX_SetTopItem( wnd, descr, descr->top_item + 1, TRUE ); - break; - case SB_PAGEUP: - LISTBOX_SetTopItem( wnd, descr, descr->top_item - - LISTBOX_GetCurrentPageSize( wnd, descr ), TRUE ); - break; - case SB_PAGEDOWN: - LISTBOX_SetTopItem( wnd, descr, descr->top_item + - LISTBOX_GetCurrentPageSize( wnd, descr ), TRUE ); - break; - case SB_THUMBPOSITION: - LISTBOX_SetTopItem( wnd, descr, HIWORD(wParam), TRUE ); - break; - case SB_THUMBTRACK: - info.cbSize = sizeof(info); - info.fMask = SIF_TRACKPOS; - GetScrollInfo( wnd->hwndSelf, SB_VERT, &info ); - LISTBOX_SetTopItem( wnd, descr, info.nTrackPos, TRUE ); - break; - case SB_TOP: - LISTBOX_SetTopItem( wnd, descr, 0, TRUE ); - break; - case SB_BOTTOM: - LISTBOX_SetTopItem( wnd, descr, descr->nb_items, TRUE ); - break; - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_HandleHScroll - */ -static LRESULT LISTBOX_HandleHScroll( WND *wnd, LB_DESCR *descr, - WPARAM wParam, LPARAM lParam ) -{ - SCROLLINFO info; - INT page; - - if (descr->style & LBS_MULTICOLUMN) - { - switch(LOWORD(wParam)) - { - case SB_LINELEFT: - LISTBOX_SetTopItem( wnd, descr, descr->top_item-descr->page_size, - TRUE ); - break; - case SB_LINERIGHT: - LISTBOX_SetTopItem( wnd, descr, descr->top_item+descr->page_size, - TRUE ); - break; - case SB_PAGELEFT: - page = descr->width / descr->column_width; - if (page < 1) page = 1; - LISTBOX_SetTopItem( wnd, descr, - descr->top_item - page * descr->page_size, TRUE ); - break; - case SB_PAGERIGHT: - page = descr->width / descr->column_width; - if (page < 1) page = 1; - LISTBOX_SetTopItem( wnd, descr, - descr->top_item + page * descr->page_size, TRUE ); - break; - case SB_THUMBPOSITION: - LISTBOX_SetTopItem( wnd, descr, HIWORD(wParam)*descr->page_size, - TRUE ); - break; - case SB_THUMBTRACK: - info.cbSize = sizeof(info); - info.fMask = SIF_TRACKPOS; - GetScrollInfo( wnd->hwndSelf, SB_VERT, &info ); - LISTBOX_SetTopItem( wnd, descr, info.nTrackPos*descr->page_size, - TRUE ); - break; - case SB_LEFT: - LISTBOX_SetTopItem( wnd, descr, 0, TRUE ); - break; - case SB_RIGHT: - LISTBOX_SetTopItem( wnd, descr, descr->nb_items, TRUE ); - break; - } - } - else if (descr->horz_extent) - { - switch(LOWORD(wParam)) - { - case SB_LINELEFT: - LISTBOX_SetHorizontalPos( wnd, descr, descr->horz_pos - 1 ); - break; - case SB_LINERIGHT: - LISTBOX_SetHorizontalPos( wnd, descr, descr->horz_pos + 1 ); - break; - case SB_PAGELEFT: - LISTBOX_SetHorizontalPos( wnd, descr, - descr->horz_pos - descr->width ); - break; - case SB_PAGERIGHT: - LISTBOX_SetHorizontalPos( wnd, descr, - descr->horz_pos + descr->width ); - break; - case SB_THUMBPOSITION: - LISTBOX_SetHorizontalPos( wnd, descr, HIWORD(wParam) ); - break; - case SB_THUMBTRACK: - info.cbSize = sizeof(info); - info.fMask = SIF_TRACKPOS; - GetScrollInfo( wnd->hwndSelf, SB_HORZ, &info ); - LISTBOX_SetHorizontalPos( wnd, descr, info.nTrackPos ); - break; - case SB_LEFT: - LISTBOX_SetHorizontalPos( wnd, descr, 0 ); - break; - case SB_RIGHT: - LISTBOX_SetHorizontalPos( wnd, descr, - descr->horz_extent - descr->width ); - break; - } - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_HandleLButtonDown - */ -static LRESULT LISTBOX_HandleLButtonDown( WND *wnd, LB_DESCR *descr, - WPARAM wParam, INT x, INT y ) -{ - INT index = LISTBOX_GetItemFromPoint( wnd, descr, x, y ); - DPRINT( "[%04x]: lbuttondown %d,%d item %d\n", - wnd->hwndSelf, x, y, index ); - if (!descr->caret_on && (GetFocus() == wnd->hwndSelf)) return 0; - if (index != -1) - { - if (descr->style & LBS_EXTENDEDSEL) - { - if (!(wParam & MK_SHIFT)) descr->anchor_item = index; - if (wParam & MK_CONTROL) - { - LISTBOX_SetCaretIndex( wnd, descr, index, FALSE ); - LISTBOX_SetSelection( wnd, descr, index, - !descr->items[index].selected, FALSE ); - } - else LISTBOX_MoveCaret( wnd, descr, index, FALSE ); - } - else - { - LISTBOX_MoveCaret( wnd, descr, index, FALSE ); - LISTBOX_SetSelection( wnd, descr, index, - (!(descr->style & LBS_MULTIPLESEL) || - !descr->items[index].selected), FALSE ); - } - } - - if( !descr->lphc ) SetFocus( wnd->hwndSelf ); - else SetFocus( (descr->lphc->hWndEdit) ? descr->lphc->hWndEdit - : descr->lphc->self->hwndSelf ) ; - - SetCapture( wnd->hwndSelf ); - if (index != -1 && !descr->lphc) - { - if (descr->style & LBS_NOTIFY ) - SendMessageA( descr->owner, WM_LBTRACKPOINT, index, - MAKELPARAM( x, y ) ); - if (wnd->dwExStyle & WS_EX_DRAGDETECT) - { - POINT pt = { x, y }; - // if (DragDetect( wnd->hwndSelf, pt )) - SendMessageA( descr->owner, WM_BEGINDRAG, 0, 0 ); - } - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_HandleLButtonUp - */ -static LRESULT LISTBOX_HandleLButtonUp( WND *wnd, LB_DESCR *descr ) -{ - if (LISTBOX_Timer != LB_TIMER_NONE) - KillTimer( wnd->hwndSelf, LB_TIMER_ID ); - LISTBOX_Timer = LB_TIMER_NONE; - if (GetCapture() == wnd->hwndSelf) - { - ReleaseCapture(); - if (descr->style & LBS_NOTIFY) - SEND_NOTIFICATION( wnd, descr, LBN_SELCHANGE ); - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_HandleTimer - * - * Handle scrolling upon a timer event. - * Return TRUE if scrolling should continue. - */ -static LRESULT LISTBOX_HandleTimer( WND *wnd, LB_DESCR *descr, - INT index, TIMER_DIRECTION dir ) -{ - switch(dir) - { - case LB_TIMER_UP: - if (descr->top_item) index = descr->top_item - 1; - else index = 0; - break; - case LB_TIMER_LEFT: - if (descr->top_item) index -= descr->page_size; - break; - case LB_TIMER_DOWN: - index = descr->top_item + LISTBOX_GetCurrentPageSize( wnd, descr ); - if (index == descr->focus_item) index++; - if (index >= descr->nb_items) index = descr->nb_items - 1; - break; - case LB_TIMER_RIGHT: - if (index + descr->page_size < descr->nb_items) - index += descr->page_size; - break; - case LB_TIMER_NONE: - break; - } - if (index == descr->focus_item) return FALSE; - LISTBOX_MoveCaret( wnd, descr, index, FALSE ); - return TRUE; -} - - -/*********************************************************************** - * LISTBOX_HandleSystemTimer - * - * WM_SYSTIMER handler. - */ -static LRESULT LISTBOX_HandleSystemTimer( WND *wnd, LB_DESCR *descr ) -{ - if (!LISTBOX_HandleTimer( wnd, descr, descr->focus_item, LISTBOX_Timer )) - { - KillTimer( wnd->hwndSelf, LB_TIMER_ID ); - LISTBOX_Timer = LB_TIMER_NONE; - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_HandleMouseMove - * - * WM_MOUSEMOVE handler. - */ -static void LISTBOX_HandleMouseMove( WND *wnd, LB_DESCR *descr, - INT x, INT y ) -{ - INT index; - TIMER_DIRECTION dir; - - if (descr->style & LBS_MULTICOLUMN) - { - if (y < 0) y = 0; - else if (y >= descr->item_height * descr->page_size) - y = descr->item_height * descr->page_size - 1; - - if (x < 0) - { - dir = LB_TIMER_LEFT; - x = 0; - } - else if (x >= descr->width) - { - dir = LB_TIMER_RIGHT; - x = descr->width - 1; - } - else dir = LB_TIMER_NONE; /* inside */ - } - else - { - if (y < 0) dir = LB_TIMER_UP; /* above */ - else if (y >= descr->height) dir = LB_TIMER_DOWN; /* below */ - else dir = LB_TIMER_NONE; /* inside */ - } - - index = LISTBOX_GetItemFromPoint( wnd, descr, x, y ); - if (index == -1) index = descr->focus_item; - if (!LISTBOX_HandleTimer( wnd, descr, index, dir )) dir = LB_TIMER_NONE; - - /* Start/stop the system timer */ - - if (dir != LB_TIMER_NONE) - SetTimer( wnd->hwndSelf, LB_TIMER_ID, LB_SCROLL_TIMEOUT, NULL); - else if (LISTBOX_Timer != LB_TIMER_NONE) - KillTimer( wnd->hwndSelf, LB_TIMER_ID ); - LISTBOX_Timer = dir; -} - - -/*********************************************************************** - * LISTBOX_HandleKeyDown - */ -static LRESULT LISTBOX_HandleKeyDown( WND *wnd, LB_DESCR *descr, WPARAM wParam ) -{ - INT caret = -1; - if (descr->style & LBS_WANTKEYBOARDINPUT) - { - caret = SendMessageA( descr->owner, WM_VKEYTOITEM, - MAKEWPARAM(LOWORD(wParam), descr->focus_item), - wnd->hwndSelf ); - if (caret == -2) return 0; - } - if (caret == -1) switch(wParam) - { - case VK_LEFT: - if (descr->style & LBS_MULTICOLUMN) - { - if (descr->focus_item >= descr->page_size) - caret = descr->focus_item - descr->page_size; - break; - } - /* fall through */ - case VK_UP: - caret = descr->focus_item - 1; - if (caret < 0) caret = 0; - break; - case VK_RIGHT: - if (descr->style & LBS_MULTICOLUMN) - { - if (descr->focus_item + descr->page_size < descr->nb_items) - caret = descr->focus_item + descr->page_size; - break; - } - /* fall through */ - case VK_DOWN: - caret = descr->focus_item + 1; - if (caret >= descr->nb_items) caret = descr->nb_items - 1; - break; - case VK_PRIOR: - if (descr->style & LBS_MULTICOLUMN) - { - INT page = descr->width / descr->column_width; - if (page < 1) page = 1; - caret = descr->focus_item - (page * descr->page_size) + 1; - } - else caret = descr->focus_item-LISTBOX_GetCurrentPageSize(wnd,descr)+1; - if (caret < 0) caret = 0; - break; - case VK_NEXT: - if (descr->style & LBS_MULTICOLUMN) - { - INT page = descr->width / descr->column_width; - if (page < 1) page = 1; - caret = descr->focus_item + (page * descr->page_size) - 1; - } - else caret = descr->focus_item+LISTBOX_GetCurrentPageSize(wnd,descr)-1; - if (caret >= descr->nb_items) caret = descr->nb_items - 1; - break; - case VK_HOME: - caret = 0; - break; - case VK_END: - caret = descr->nb_items - 1; - break; - case VK_SPACE: - if (descr->style & LBS_EXTENDEDSEL) caret = descr->focus_item; - else if (descr->style & LBS_MULTIPLESEL) - { - LISTBOX_SetSelection( wnd, descr, descr->focus_item, - !descr->items[descr->focus_item].selected, - (descr->style & LBS_NOTIFY) != 0 ); - } - else if (descr->selected_item == -1) - { - LISTBOX_SetSelection( wnd, descr, descr->focus_item, TRUE, - (descr->style & LBS_NOTIFY) != 0 ); - } - break; - } - if (caret >= 0) - { - if ((descr->style & LBS_EXTENDEDSEL) && - !(GetKeyState( VK_SHIFT ) & 0x8000)) - descr->anchor_item = caret; - LISTBOX_MoveCaret( wnd, descr, caret, TRUE ); - if (descr->style & LBS_NOTIFY) - { - if( descr->lphc && CB_GETTYPE(descr->lphc) != CBS_SIMPLE ) - { - /* make sure that combo parent doesn't hide us */ - descr->lphc->wState |= CBF_NOROLLUP; - } - SEND_NOTIFICATION( wnd, descr, LBN_SELCHANGE ); - } - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_HandleChar - */ -static LRESULT LISTBOX_HandleChar( WND *wnd, LB_DESCR *descr, - WPARAM wParam ) -{ - INT caret = -1; - char str[2] = { wParam & 0xff, '\0' }; - - if (descr->style & LBS_WANTKEYBOARDINPUT) - { - caret = SendMessageA( descr->owner, WM_CHARTOITEM, - MAKEWPARAM(LOWORD(wParam), descr->focus_item), - wnd->hwndSelf ); - if (caret == -2) return 0; - } - if (caret == -1) - caret = LISTBOX_FindString( wnd, descr, descr->focus_item, str, FALSE); - if (caret != -1) - { - LISTBOX_MoveCaret( wnd, descr, caret, TRUE ); - if (descr->style & LBS_NOTIFY) - SEND_NOTIFICATION( wnd, descr, LBN_SELCHANGE ); - } - return 0; -} - - -/*********************************************************************** - * LISTBOX_Create - */ -static BOOL LISTBOX_Create( WND *wnd, LPHEADCOMBO lphc ) -{ - LB_DESCR *descr; - MEASUREITEMSTRUCT mis; - RECT rect; - - if (!(descr = HeapAlloc( GetProcessHeap(), 0, sizeof(*descr) ))) - return FALSE; - if (!(descr->heap = HeapCreate( 0, 0x10000, 0 ))) - { - HeapFree( GetProcessHeap(), 0, descr ); - return FALSE; - } - GetClientRect( wnd->hwndSelf, &rect ); - descr->owner = GetParent( wnd->hwndSelf ); - descr->style = wnd->dwStyle; - descr->width = rect.right - rect.left; - descr->height = rect.bottom - rect.top; - descr->items = NULL; - descr->nb_items = 0; - descr->top_item = 0; - descr->selected_item = -1; - descr->focus_item = 0; - descr->anchor_item = -1; - descr->item_height = 1; - descr->page_size = 1; - descr->column_width = 150; - descr->horz_extent = (wnd->dwStyle & WS_HSCROLL) ? 1 : 0; - descr->horz_pos = 0; - descr->nb_tabs = 0; - descr->tabs = NULL; - descr->caret_on = TRUE; - descr->font = 0; - descr->locale = 0; /* FIXME */ - descr->lphc = lphc; - - if( lphc ) - { - DPRINT("[%04x]: resetting owner %04x -> %04x\n", - wnd->hwndSelf, descr->owner, lphc->self->hwndSelf ); - descr->owner = lphc->self->hwndSelf; - } - - *(LB_DESCR **)wnd->wExtra = descr; - -/* if (wnd->dwExStyle & WS_EX_NOPARENTNOTIFY) descr->style &= ~LBS_NOTIFY; - */ - if (descr->style & LBS_EXTENDEDSEL) descr->style |= LBS_MULTIPLESEL; - if (descr->style & LBS_MULTICOLUMN) descr->style &= ~LBS_OWNERDRAWVARIABLE; - if (descr->style & LBS_OWNERDRAWVARIABLE) descr->style |= LBS_NOINTEGRALHEIGHT; - descr->item_height = LISTBOX_SetFont( wnd, descr, 0 ); - - if (descr->style & LBS_OWNERDRAWFIXED) - { - if( descr->lphc && (descr->lphc->dwStyle & CBS_DROPDOWN)) - { - /* WinWord gets VERY unhappy if we send WM_MEASUREITEM from here */ - descr->item_height = lphc->RectButton.bottom - lphc->RectButton.top - 6; - } - else - { - UINT id = (descr->lphc ) ? ID_CB_LISTBOX : wnd->wIDmenu; - - mis.CtlType = ODT_LISTBOX; - mis.CtlID = id; - mis.itemID = -1; - mis.itemWidth = 0; - mis.itemData = 0; - mis.itemHeight = descr->item_height; - SendMessageA( descr->owner, WM_MEASUREITEM, id, (LPARAM)&mis ); - descr->item_height = mis.itemHeight ? mis.itemHeight : 1; - } - } - - return TRUE; -} - - -/*********************************************************************** - * LISTBOX_Destroy - */ -static BOOL LISTBOX_Destroy( WND *wnd, LB_DESCR *descr ) -{ - LISTBOX_ResetContent( wnd, descr ); - HeapDestroy( descr->heap ); - HeapFree( GetProcessHeap(), 0, descr ); - wnd->wExtra[0] = 0; - return TRUE; -} - - -/*********************************************************************** - * ListBoxWndProc - */ -LRESULT WINAPI ListBoxWndProc( HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam ) -{ - LRESULT ret; - LB_DESCR *descr; - WND *wnd = WIN_FindWndPtr( hwnd ); - - if (!wnd) return 0; - if (!(descr = *(LB_DESCR **)wnd->wExtra)) - { - if (msg == WM_CREATE) - { - if (!LISTBOX_Create( wnd, NULL )) return -1; - DPRINT( "creating wnd=%04x descr=%p\n", - hwnd, *(LB_DESCR **)wnd->wExtra ); - return 0; - } - /* Ignore all other messages before we get a WM_CREATE */ - return DefWindowProcA( hwnd, msg, wParam, lParam ); - } - - DPRINT( "[%04x]: msg %s wp %08x lp %08lx\n", - wnd->hwndSelf, SPY_GetMsgName(msg), wParam, lParam ); - switch(msg) - { - case LB_RESETCONTENT: - LISTBOX_ResetContent( wnd, descr ); - return 0; - - case LB_ADDSTRING: - wParam = LISTBOX_FindStringPos( wnd, descr, (LPCSTR)lParam, FALSE ); - return LISTBOX_InsertString( wnd, descr, wParam, (LPCSTR)lParam ); - - case LB_INSERTSTRING: - return LISTBOX_InsertString( wnd, descr, wParam, (LPCSTR)lParam ); - - - case LB_ADDFILE: - wParam = LISTBOX_FindFileStrPos( wnd, descr, (LPCSTR)lParam ); - return LISTBOX_InsertString( wnd, descr, wParam, (LPCSTR)lParam ); - - case LB_DELETESTRING: - return LISTBOX_RemoveItem( wnd, descr, wParam ); - - case LB_GETITEMDATA: - if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) - return LB_ERR; - return descr->items[wParam].data; - - case LB_SETITEMDATA: - if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) - return LB_ERR; - descr->items[wParam].data = (DWORD)lParam; - return LB_OKAY; - - case LB_GETCOUNT: - return descr->nb_items; - - case LB_GETTEXT: - return LISTBOX_GetText( wnd, descr, wParam, (LPSTR)lParam ); - - case LB_GETTEXTLEN: - if (wParam >= descr->nb_items) return LB_ERR; - return (HAS_STRINGS(descr) ? strlen(descr->items[wParam].str) - : sizeof(DWORD)); - - - case LB_GETCURSEL: - return descr->selected_item; - - - case LB_GETTOPINDEX: - return descr->top_item; - - case LB_GETITEMHEIGHT: - return LISTBOX_GetItemHeight( wnd, descr, wParam ); - - - case LB_SETITEMHEIGHT: - return LISTBOX_SetItemHeight( wnd, descr, wParam, lParam ); - - case LB_ITEMFROMPOINT: - { - POINT pt = { LOWORD(lParam), HIWORD(lParam) }; - RECT rect = { 0, 0, descr->width, descr->height }; - return MAKELONG( LISTBOX_GetItemFromPoint(wnd, descr, pt.x, pt.y), - PtInRect( &rect, pt ) ); - } - - - case LB_SETCARETINDEX: - return LISTBOX_SetCaretIndex( wnd, descr, wParam, !lParam ); - - - case LB_GETCARETINDEX: - return descr->focus_item; - - - case LB_SETTOPINDEX: - return LISTBOX_SetTopItem( wnd, descr, wParam, TRUE ); - - - case LB_SETCOLUMNWIDTH: - return LISTBOX_SetColumnWidth( wnd, descr, wParam ); - - - - case LB_GETITEMRECT: - return LISTBOX_GetItemRect( wnd, descr, wParam, (RECT *)lParam ); - - - case LB_FINDSTRING: - return LISTBOX_FindString( wnd, descr, wParam, (LPCSTR)lParam, FALSE ); - - - case LB_FINDSTRINGEXACT: - return LISTBOX_FindString( wnd, descr, wParam, (LPCSTR)lParam, TRUE ); - - - case LB_SELECTSTRING: - { - INT index = LISTBOX_FindString( wnd, descr, wParam, - (LPCSTR)lParam, FALSE ); - if (index == LB_ERR) return LB_ERR; - LISTBOX_SetSelection( wnd, descr, index, TRUE, FALSE ); - return index; - } - - - case LB_GETSEL: - if (((INT)wParam < 0) || ((INT)wParam >= descr->nb_items)) - return LB_ERR; - return descr->items[wParam].selected; - - case LB_SETSEL: - return LISTBOX_SetSelection( wnd, descr, lParam, wParam, FALSE ); - - - case LB_SETCURSEL: - LISTBOX_SetCaretIndex( wnd, descr, wParam, TRUE ); - return LISTBOX_SetSelection( wnd, descr, wParam, TRUE, FALSE ); - - case LB_GETSELCOUNT: - return LISTBOX_GetSelCount( wnd, descr ); - - - case LB_GETSELITEMS: - return LISTBOX_GetSelItems( wnd, descr, wParam, (LPINT)lParam ); - - case LB_SELITEMRANGE: - if (LOWORD(lParam) <= HIWORD(lParam)) - return LISTBOX_SelectItemRange( wnd, descr, LOWORD(lParam), - HIWORD(lParam), wParam ); - else - return LISTBOX_SelectItemRange( wnd, descr, HIWORD(lParam), - LOWORD(lParam), wParam ); - - - case LB_SELITEMRANGEEX: - if ((INT)lParam >= (INT)wParam) - return LISTBOX_SelectItemRange( wnd, descr, wParam, lParam, TRUE ); - else - return LISTBOX_SelectItemRange( wnd, descr, lParam, wParam, FALSE); - - - case LB_GETHORIZONTALEXTENT: - return descr->horz_extent; - - - case LB_SETHORIZONTALEXTENT: - return LISTBOX_SetHorizontalExtent( wnd, descr, wParam ); - - case LB_GETANCHORINDEX: - return descr->anchor_item; - - - case LB_SETANCHORINDEX: - if (((INT)wParam < -1) || ((INT)wParam >= descr->nb_items)) - return LB_ERR; - descr->anchor_item = (INT)wParam; - return LB_OKAY; - - - - case LB_DIR: - return LISTBOX_Directory( wnd, descr, wParam, (LPCSTR)lParam, TRUE ); - - case LB_GETLOCALE: - return descr->locale; - - case LB_SETLOCALE: - descr->locale = (LCID)wParam; /* FIXME: should check for valid lcid */ - return LB_OKAY; - - case LB_INITSTORAGE: - return LISTBOX_InitStorage( wnd, descr, wParam, (DWORD)lParam ); - - case LB_SETCOUNT: - return LISTBOX_SetCount( wnd, descr, (INT)wParam ); - - - - case LB_SETTABSTOPS: - return LISTBOX_SetTabStops( wnd, descr, wParam, - (LPINT)lParam, FALSE ); - - - case LB_CARETON: - if (descr->caret_on) return LB_OKAY; - descr->caret_on = TRUE; - if ((descr->focus_item != -1) && (GetFocus() == wnd->hwndSelf)) - LISTBOX_RepaintItem( wnd, descr, descr->focus_item, ODA_FOCUS ); - return LB_OKAY; - - - case LB_CARETOFF: - if (!descr->caret_on) return LB_OKAY; - descr->caret_on = FALSE; - if ((descr->focus_item != -1) && (GetFocus() == wnd->hwndSelf)) - LISTBOX_RepaintItem( wnd, descr, descr->focus_item, ODA_FOCUS ); - return LB_OKAY; - - case WM_DESTROY: - return LISTBOX_Destroy( wnd, descr ); - - case WM_ENABLE: - InvalidateRect( hwnd, NULL, TRUE ); - return 0; - - case WM_SETREDRAW: - LISTBOX_SetRedraw( wnd, descr, wParam != 0 ); - return 0; - - case WM_GETDLGCODE: - return DLGC_WANTARROWS | DLGC_WANTCHARS; - - case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc = ( wParam ) ? ((HDC)wParam) - : BeginPaint( hwnd, &ps ); - ret = LISTBOX_Paint( wnd, descr, hdc ); - if( !wParam ) EndPaint( hwnd, &ps ); - } - return ret; - - case WM_SIZE: - LISTBOX_UpdateSize( wnd, descr ); - return 0; - - case WM_GETFONT: - return descr->font; - - case WM_SETFONT: - LISTBOX_SetFont( wnd, descr, (HFONT)wParam ); - if (lParam) InvalidateRect( wnd->hwndSelf, 0, TRUE ); - return 0; - - case WM_SETFOCUS: - descr->caret_on = TRUE; - if (descr->focus_item != -1) - LISTBOX_RepaintItem( wnd, descr, descr->focus_item, ODA_FOCUS ); - SEND_NOTIFICATION( wnd, descr, LBN_SETFOCUS ); - return 0; - - case WM_KILLFOCUS: - if ((descr->focus_item != -1) && descr->caret_on) - LISTBOX_RepaintItem( wnd, descr, descr->focus_item, ODA_FOCUS ); - SEND_NOTIFICATION( wnd, descr, LBN_KILLFOCUS ); - return 0; - - case WM_HSCROLL: - return LISTBOX_HandleHScroll( wnd, descr, wParam, lParam ); - - case WM_VSCROLL: - return LISTBOX_HandleVScroll( wnd, descr, wParam, lParam ); - - case WM_LBUTTONDOWN: - return LISTBOX_HandleLButtonDown( wnd, descr, wParam, - (INT)LOWORD(lParam), - (INT)HIWORD(lParam) ); - - case WM_LBUTTONDBLCLK: - if (descr->style & LBS_NOTIFY) - SEND_NOTIFICATION( wnd, descr, LBN_DBLCLK ); - return 0; - - case WM_MOUSEMOVE: - if (GetCapture() == hwnd) - LISTBOX_HandleMouseMove( wnd, descr, (INT)LOWORD(lParam), - (INT)HIWORD(lParam) ); - return 0; - - case WM_LBUTTONUP: - return LISTBOX_HandleLButtonUp( wnd, descr ); - - case WM_KEYDOWN: - return LISTBOX_HandleKeyDown( wnd, descr, wParam ); - - case WM_CHAR: - return LISTBOX_HandleChar( wnd, descr, wParam ); - - case WM_SYSTIMER: - return LISTBOX_HandleSystemTimer( wnd, descr ); - - case WM_ERASEBKGND: - if (IS_OWNERDRAW(descr)) - { - RECT rect = { 0, 0, descr->width, descr->height }; - HBRUSH hbrush = SendMessageA( descr->owner, WM_CTLCOLORLISTBOX, - wParam, (LPARAM)wnd->hwndSelf ); - if (hbrush) FillRect( (HDC)wParam, &rect, hbrush ); - } - return 1; - - case WM_DROPFILES: - if( !descr->lphc ) - return SendMessageA( descr->owner, msg, wParam, lParam ); - break; - - case WM_DROPOBJECT: - case WM_QUERYDROPOBJECT: - case WM_DRAGSELECT: - case WM_DRAGMOVE: - if( !descr->lphc ) - { - // LPDRAGINFO dragInfo = (LPDRAGINFO)lParam; - // dragInfo->l = LISTBOX_GetItemFromPoint( wnd, descr, dragInfo->pt.x, - // dragInfo->pt.y ); - return SendMessageA( descr->owner, msg, wParam, lParam ); - } - break; - - case WM_NCCREATE: - if (TWEAK_WineLook > WIN31_LOOK) - wnd->dwExStyle |= WS_EX_CLIENTEDGE; - return DefWindowProcA( hwnd, msg, wParam, lParam ); - - default: - if ((msg >= WM_USER) && (msg < 0xc000)) - DPRINT( "[%04x]: unknown msg %04x wp %08x lp %08lx\n", - hwnd, msg, wParam, lParam ); - return DefWindowProcA( hwnd, msg, wParam, lParam ); - } - return 0; -} - -/*********************************************************************** - * COMBO_Directory - */ -LRESULT COMBO_Directory( LPHEADCOMBO lphc, UINT attrib, LPSTR dir, BOOL bLong) -{ - WND *wnd = WIN_FindWndPtr( lphc->hWndLBox ); - - if( wnd ) - { - LB_DESCR *descr = *(LB_DESCR **)wnd->wExtra; - if( descr ) - { - LRESULT lRet = LISTBOX_Directory( wnd, descr, attrib, dir, bLong ); - - RedrawWindow( lphc->self->hwndSelf, NULL, 0, - RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW ); - return lRet; - } - } - return CB_ERR; -} - -/*********************************************************************** - * ComboLBWndProc - * - * NOTE: in Windows, winproc address of the ComboLBox is the same - * as that of the Listbox. - */ -LRESULT WINAPI ComboLBWndProc( HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam ) -{ - LRESULT lRet = 0; - WND *wnd = WIN_FindWndPtr( hwnd ); - - if (wnd) - { - LB_DESCR *descr = *(LB_DESCR **)wnd->wExtra; - - DPRINT( "[%04x]: msg %s wp %08x lp %08lx\n", - wnd->hwndSelf, SPY_GetMsgName(msg), wParam, lParam ); - - if( descr || msg == WM_CREATE ) - { - LPHEADCOMBO lphc = (descr) ? descr->lphc : NULL; - - switch( msg ) - { - case WM_CREATE: -#define lpcs ((LPCREATESTRUCT)lParam) - DPRINT( "\tpassed parent handle = 0x%08x\n", - (UINT)lpcs->lpCreateParams); - - lphc = (LPHEADCOMBO)(lpcs->lpCreateParams); -#undef lpcs - return LISTBOX_Create( wnd, lphc ); - - case WM_LBUTTONDOWN: - return LISTBOX_HandleLButtonDown( wnd, descr, wParam, - (INT)LOWORD(lParam), (INT)HIWORD(lParam)); - - /* avoid activation at all costs */ - - case WM_MOUSEACTIVATE: - return MA_NOACTIVATE; - - case WM_NCACTIVATE: - return FALSE; - - case WM_KEYDOWN: - if( CB_GETTYPE(lphc) != CBS_SIMPLE ) - { - /* for some reason(?) Windows makes it possible to - * show/hide ComboLBox by sending it WM_KEYDOWNs */ - - if( (!(lphc->wState & CBF_EUI) && wParam == VK_F4) || - ( (lphc->wState & CBF_EUI) && !(lphc->wState & CBF_DROPPED) - && (wParam == VK_DOWN || wParam == VK_UP)) ) - { - COMBO_FlipListbox( lphc, FALSE ); - return 0; - } - } - return LISTBOX_HandleKeyDown( wnd, descr, wParam ); - - case LB_SETCURSEL: - lRet = ListBoxWndProc( hwnd, msg, wParam, lParam ); - return (lRet == LB_ERR) ? lRet : descr->selected_item; - - case WM_NCDESTROY: - if( CB_GETTYPE(lphc) != CBS_SIMPLE ) - lphc->hWndLBox = 0; - /* fall through */ - - default: - return ListBoxWndProc( hwnd, msg, wParam, lParam ); - } - } - lRet = DefWindowProcA( hwnd, msg, wParam, lParam ); - - DPRINT("\t default on msg [%04x]\n", (UINT)msg ); - } - - return lRet; -} - diff --git a/reactos/lib/user32/controls/menu.c b/reactos/lib/user32/controls/menu.c deleted file mode 100644 index dfa1753d930..00000000000 --- a/reactos/lib/user32/controls/menu.c +++ /dev/null @@ -1,1345 +0,0 @@ -/* - * Menu functions - * - * Copyright 1993 Martin Ayotte - * Copyright 1994 Alexandre Julliard - * Copyright 1997 Morten Welinder - */ - -/* - * Note: the style MF_MOUSESELECT is used to mark popup items that - * have been selected, i.e. their popup menu is currently displayed. - * This is probably not the meaning this style has in MS-Windows. - */ - -#include - -#include -#include -#include - - -#include -#include -#include -#include -#include -#include -#include - - - - -/********************************************************************** - * CreateMenu (USER32.81) - */ -HMENU STDCALL CreateMenu(void) -{ - HMENU hMenu; - LPPOPUPMENU menu; - if (!(menu = HeapAlloc(GetProcessHeap(),0,sizeof(POPUPMENU) ) ) ) - return (HMENU)NULL; - hMenu = (HANDLE)menu; - menu->wFlags = 0; - menu->wMagic = MENU_MAGIC; - menu->hTaskQ = 0; - menu->Width = 0; - menu->Height = 0; - menu->nItems = 0; - menu->hWnd = 0; - menu->items = NULL; - menu->FocusedItem = NO_SELECTED_ITEM; - DPRINT( "return %04x\n", hMenu ); - return hMenu; -} - - - - - -/********************************************************************** - * DestroyMenu (USER32.134) - */ -WINBOOL STDCALL DestroyMenu( HMENU hMenu ) -{ - DPRINT("menu (%04x)\n", (UINT)hMenu); - - /* Silently ignore attempts to destroy default system popup */ - - if (hMenu && hMenu != MENU_DefSysPopup) - { - LPPOPUPMENU lppop = (LPPOPUPMENU) (hMenu); - - if( pTopPopupWnd && (hMenu == *(HMENU*)pTopPopupWnd->wExtra) ) - *(UINT*)pTopPopupWnd->wExtra = 0; - - if (IS_A_MENU( lppop )) - { - lppop->wMagic = 0; /* Mark it as destroyed */ - - if ((lppop->wFlags & MF_POPUP) && lppop->hWnd && - (!pTopPopupWnd || (lppop->hWnd != pTopPopupWnd->hwndSelf))) - DestroyWindow( lppop->hWnd ); - - if (lppop->items) /* recursively destroy submenus */ - { - int i; - MENUITEM *item = lppop->items; - for (i = lppop->nItems; i > 0; i--, item++) - { - if (item->fType & MF_POPUP) DestroyMenu(item->hSubMenu); - MENU_FreeItemData( item ); - } - HeapFree( GetProcessHeap(), 0, lppop->items ); - } - HeapFree( GetProcessHeap(),0,hMenu ); - } - else return FALSE; - } - return (hMenu != MENU_DefSysPopup); -} - - - - - -/********************************************************************** - * GetSystemMenu (USER32.291) - */ -HMENU STDCALL GetSystemMenu( HWND hWnd, WINBOOL bRevert ) -{ - WND *wndPtr = WIN_FindWndPtr( hWnd ); - - if (wndPtr) - { - if( wndPtr->hSysMenu ) - { - if( bRevert ) - { - DestroyMenu(wndPtr->hSysMenu); - wndPtr->hSysMenu = 0; - } - else - { - POPUPMENU *menu = (POPUPMENU*)(wndPtr->hSysMenu); - if( menu->items[0].hSubMenu == MENU_DefSysPopup ) - menu->items[0].hSubMenu = MENU_CopySysPopup(); - } - } - - if(!wndPtr->hSysMenu && (wndPtr->dwStyle & WS_SYSMENU) ) - wndPtr->hSysMenu = MENU_GetSysMenu( hWnd, (HMENU)(-1) ); - - if( wndPtr->hSysMenu ) - return GetSubMenu(wndPtr->hSysMenu, 0); - } - return 0; -} - - - - - -/******************************************************************* - * SetSystemMenu (USER32.508) - */ -WINBOOL STDCALL SetSystemMenu( HWND hwnd, HMENU hMenu ) -{ - WND *wndPtr = WIN_FindWndPtr(hwnd); - - if (wndPtr) - { - if (wndPtr->hSysMenu) - DestroyMenu( wndPtr->hSysMenu ); - wndPtr->hSysMenu = MENU_GetSysMenu( hwnd, hMenu ); - return TRUE; - } - return FALSE; -} - - - - -/********************************************************************** - * GetMenu (USER32.257) - */ -HMENU STDCALL GetMenu( HWND hWnd ) -{ - WND * wndPtr = WIN_FindWndPtr(hWnd); - if (wndPtr && !(wndPtr->dwStyle & WS_CHILD)) - return (HMENU)wndPtr->wIDmenu; - return 0; -} - - - - -/********************************************************************** - * SetMenu (USER32.487) - */ -WINBOOL STDCALL SetMenu( HWND hWnd, HMENU hMenu ) -{ - WND * wndPtr = WIN_FindWndPtr(hWnd); - - DPRINT("menu (%04x, %04x);\n", (UINT)hWnd, (UINT)hMenu); - - if (wndPtr && !(wndPtr->dwStyle & WS_CHILD)) - { - if (GetCapture() == hWnd) ReleaseCapture(); - - wndPtr->wIDmenu = (UINT)hMenu; - if (hMenu != 0) - { - LPPOPUPMENU lpmenu; - - if (!(lpmenu = (LPPOPUPMENU)(hMenu))) - return FALSE; - lpmenu->hWnd = hWnd; - lpmenu->wFlags &= ~MF_POPUP; /* Can't be a popup */ - lpmenu->Height = 0; /* Make sure we recalculate the size */ - } - if (IsWindowVisible(hWnd)) - SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | - SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); - return TRUE; - } - return FALSE; -} - - - -/********************************************************************** - * GetSubMenu (USER32.288) - */ -HMENU STDCALL GetSubMenu( HMENU hMenu, INT nPos ) -{ - LPPOPUPMENU lppop; - - if (!(lppop = (LPPOPUPMENU)(hMenu))) return 0; - if ((UINT)nPos >= lppop->nItems) return 0; - if (!(lppop->items[nPos].fType & MF_POPUP)) return 0; - return lppop->items[nPos].hSubMenu; -} - - - -/********************************************************************** - * DrawMenuBar (USER32.1) - */ -WINBOOL STDCALL DrawMenuBar( HWND hWnd ) -{ - LPPOPUPMENU lppop; - WND *wndPtr = WIN_FindWndPtr(hWnd); - if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && wndPtr->wIDmenu) - { - lppop = (LPPOPUPMENU)((HMENU)wndPtr->wIDmenu); - if (lppop == NULL) return FALSE; - - lppop->Height = 0; /* Make sure we call MENU_MenuBarCalcSize */ - SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | - SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); - return TRUE; - } - return FALSE; -} - - - - - - - -/***************************************************************** - * LoadMenuA (USER32.370) - */ -HMENU STDCALL LoadMenuA( HINSTANCE instance, LPCSTR name ) -{ - - HRSRC hrsrc = FindResourceA( GetModuleHandle(NULL), name, (LPCSTR)RT_MENU ); - if (!hrsrc) return 0; - return LoadMenuIndirectA( (LPCVOID)LoadResource( GetModuleHandle(NULL), hrsrc )); -} - - -/***************************************************************** - * LoadMenuW (USER32.373) - */ -HMENU STDCALL LoadMenuW( HINSTANCE hInstance, LPCWSTR name ) -{ - - HRSRC hrsrc = FindResourceW( GetModuleHandle(NULL), name, (LPCSTR)RT_MENU ); - if (!hrsrc) return 0; - return LoadMenuIndirectW( (LPCVOID)LoadResource( GetModuleHandle(NULL), hrsrc )); -} -/* - -A menu template consists of a MENUITEMTEMPLATEHEADER structure -followed by one or more contiguous MENUITEMTEMPLATE structures. -In Windows 95, an extended menu template consists of a -MENUEX_TEMPLATE_HEADER structure followed by one or more -contiguous MENUEX_TEMPLATE_ITEM structures. - - -typedef struct { - WORD wVersion; - WORD wOffset; - DWORD dwHelpId; -} MENUEX_TEMPLATE_HEADER; - -typedef struct { - DWORD dwType; - DWORD dwState; - UINT uId; - BYTE bResInfo; - WCHAR szText[1]; - DWORD dwHelpId; -} MENUEX_TEMPLATE_ITEM; - -typedef struct tagMENUITEMINFO { - UINT cbSize; - UINT fMask; - UINT fType; - UINT fState; - UINT wID; - HMENU hSubMenu; - HBITMAP hbmpChecked; - HBITMAP hbmpUnchecked; - DWORD dwItemData; - LPTSTR dwTypeData; - UINT cch; -} MENUITEMINFO, *LPMENUITEMINFO; -typedef MENUITEMINFO CONST *LPCMENUITEMINFO; - -typedef struct { - WORD mtOption; - WORD mtID; - WCHAR mtString[1]; -} MENUITEMTEMPLATE; - -typedef struct { - WORD versionNumber; - WORD offset; -} MENUITEMTEMPLATEHEADER; -typedef VOID MENUTEMPLATE, *LPMENUTEMPLATE; - -*/ - -/********************************************************************** - * LoadMenuIndirectA (USER32.371) - */ -HMENU -STDCALL -LoadMenuIndirectA( - CONST MENUTEMPLATE *lpMenuTemplate) -{ - return NULL; -} - - -/********************************************************************** - * LoadMenuIndirectW (USER32.372) - */ -HMENU -STDCALL -LoadMenuIndirectW( - CONST MENUTEMPLATE *lpMenuTemplate) -{ - return NULL; -} - - - -/********************************************************************** - * IsMenu (USER32.346) - */ -WINBOOL STDCALL IsMenu(HMENU hMenu) -{ - POPUPMENU *pMenu = hMenu; - return ((pMenu) && (pMenu)->wMagic == MENU_MAGIC); -} - - -/********************************************************************** - * GetMenuItemInfoA (USER32.264) - */ -WINBOOL STDCALL GetMenuItemInfoA( HMENU hmenu, UINT item, WINBOOL bypos, - LPMENUITEMINFO lpmii) -{ - int len; - MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0); - // debug_print_menuitem("GetMenuItemInfo_common: ", menu, ""); - if (!menu) - return FALSE; - - if (lpmii->fMask & MIIM_TYPE) { - lpmii->fType = menu->fType; - switch (MENU_ITEM_TYPE(menu->fType)) { - case MF_STRING: - if (menu->text && lpmii->dwTypeData && lpmii->cch) { - len = min( lpmii->cch, wcslen(menu->text)); - lstrcpynWtoA((LPSTR) lpmii->dwTypeData,menu->text,len); - lpmii->cch = len; - } - break; - case MF_OWNERDRAW: - case MF_BITMAP: - lpmii->dwTypeData = (DWORD)menu->text; - break; - default: - break; - } - } - if (lpmii->fMask & MIIM_STATE) - lpmii->fState = menu->fState; - - if (lpmii->fMask & MIIM_ID) - lpmii->wID = menu->wID; - - if (lpmii->fMask & MIIM_SUBMENU) - lpmii->hSubMenu = menu->hSubMenu; - - if (lpmii->fMask & MIIM_CHECKMARKS) { - lpmii->hbmpChecked = menu->hCheckBit; - lpmii->hbmpUnchecked = menu->hUnCheckBit; - } - if (lpmii->fMask & MIIM_DATA) - lpmii->dwItemData = menu->dwItemData; - - return TRUE; - -} - -/********************************************************************** - * GetMenuItemInfoW (USER32.265) - */ -WINBOOL STDCALL GetMenuItemInfoW( HMENU hmenu, UINT item, WINBOOL bypos, - LPMENUITEMINFO lpmii) -{ - int len; - MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0); - // debug_print_menuitem("GetMenuItemInfo_common: ", menu, ""); - if (!menu) - return FALSE; - - if (lpmii->fMask & MIIM_TYPE) { - lpmii->fType = menu->fType; - switch (MENU_ITEM_TYPE(menu->fType)) { - case MF_STRING: - if (menu->text && lpmii->dwTypeData && lpmii->cch) { - len = min( lpmii->cch, wcslen(menu->text)); - lstrcpynW((LPWSTR) lpmii->dwTypeData,menu->text,len); - lpmii->cch = len; - } - break; - case MF_OWNERDRAW: - case MF_BITMAP: - lpmii->dwTypeData = (DWORD)menu->text; - break; - default: - break; - } - } - if (lpmii->fMask & MIIM_STATE) - lpmii->fState = menu->fState; - - if (lpmii->fMask & MIIM_ID) - lpmii->wID = menu->wID; - - if (lpmii->fMask & MIIM_SUBMENU) - lpmii->hSubMenu = menu->hSubMenu; - - if (lpmii->fMask & MIIM_CHECKMARKS) { - lpmii->hbmpChecked = menu->hCheckBit; - lpmii->hbmpUnchecked = menu->hUnCheckBit; - } - if (lpmii->fMask & MIIM_DATA) - lpmii->dwItemData = menu->dwItemData; - - return TRUE; -} - - - -/********************************************************************** - * SetMenuItemInfoA (USER32.491) - */ -WINBOOL STDCALL SetMenuItemInfoA(HMENU hmenu, UINT item, WINBOOL bypos, - const MENUITEMINFO *lpmiiBuf) -{ - LPMENUITEMINFO lpmii = (LPMENUITEMINFO)lpmiiBuf; - WCHAR MenuTextW[MAX_PATH]; - char *MenuTextA; - WINBOOL bRet; - int i = 0; - MenuTextA = lpmii->dwTypeData; - - lpmii->dwTypeData = MenuTextW; - while ( MenuTextA[i] != 0 && i < MAX_PATH ) - { - MenuTextW[i] = MenuTextA[i]; - i++; - } - MenuTextW[i] = 0; - lpmii->dwTypeData = MenuTextW; - bRet = SetMenuItemInfoW(hmenu, item, bypos, lpmii); - lpmii->dwTypeData = MenuTextA; - - return bRet; -} - -/********************************************************************** - * SetMenuItemInfoW (USER32.492) - */ -WINBOOL STDCALL SetMenuItemInfoW(HMENU hmenu, UINT item, WINBOOL bypos, - const MENUITEMINFO *lpmii) -{ - MENUITEM *menu = MENU_FindItem (&hmenu, &item, bypos? MF_BYPOSITION : 0); - if (!menu) return FALSE; - - if (lpmii->fMask & MIIM_TYPE) { - /* Get rid of old string. */ - if (IS_STRING_ITEM(menu->fType) && menu->text) - HeapFree(GetProcessHeap(), 0, menu->text); - - menu->fType = lpmii->fType; - menu->text = lpmii->dwTypeData; - if (IS_STRING_ITEM(menu->fType) && menu->text) { - menu->text = HeapAlloc(GetProcessHeap(), 0,(lpmii->cch + 1)*sizeof(WCHAR)); - lstrcpynW(menu->text,(LPWSTR) lpmii->dwTypeData,lpmii->cch); - } - - - } - if (lpmii->fMask & MIIM_STATE) - menu->fState = lpmii->fState; - - if (lpmii->fMask & MIIM_ID) - menu->wID = lpmii->wID; - - if (lpmii->fMask & MIIM_SUBMENU) { - menu->hSubMenu = lpmii->hSubMenu; - if (menu->hSubMenu) { - POPUPMENU *subMenu = (POPUPMENU *)((UINT)menu->hSubMenu); - if (IS_A_MENU(subMenu)) { - subMenu->wFlags |= MF_POPUP; - menu->fType |= MF_POPUP; - } - else - /* FIXME: Return an error ? */ - menu->fType &= ~MF_POPUP; - } - else - menu->fType &= ~MF_POPUP; - } - - if (lpmii->fMask & MIIM_CHECKMARKS) - { - menu->hCheckBit = lpmii->hbmpChecked; - menu->hUnCheckBit = lpmii->hbmpUnchecked; - } - if (lpmii->fMask & MIIM_DATA) - menu->dwItemData = lpmii->dwItemData; - - //debug_print_menuitem("SetMenuItemInfo_common: ", menu, ""); - return TRUE; -} - -/********************************************************************** - * SetMenuDefaultItem (USER32.489) - */ -WINBOOL STDCALL SetMenuDefaultItem(HMENU hmenu, UINT item, UINT bypos) -{ - MENUITEM *menuitem = MENU_FindItem(&hmenu, &item, bypos); - POPUPMENU *menu; - - if (!menuitem) return FALSE; - if (!(menu = (POPUPMENU *)(hmenu))) return FALSE; - - menu->defitem = item; /* position */ - - // debug_print_menuitem("SetMenuDefaultItem: ", menuitem, ""); - // FIXME(menu, "(0x%x,%d,%d), empty stub!\n", -// hmenu, item, bypos); - return TRUE; -} - -/********************************************************************** - * GetMenuDefaultItem (USER32.260) - */ -UINT STDCALL GetMenuDefaultItem(HMENU hmenu, UINT bypos, UINT flags) -{ - POPUPMENU *menu; - - if (!(menu = (POPUPMENU *)(hmenu))) - return -1; - - //FIXME(menu, "(0x%x,%d,%d), stub!\n", hmenu, bypos, flags); - -// bypos should be specified TRUE to return default item by position -// flags are ignored - - if (bypos & MF_BYPOSITION) - return menu->defitem; - else { - //FIXME (menu, "default item 0x%x\n", menu->defitem); - if ((menu->defitem > 0) && (menu->defitem < menu->nItems)) - return menu->items[menu->defitem].wID; - } - return -1; -} - - - -/********************************************************************** - * InsertMenuItemA - */ -WINBOOL STDCALL InsertMenuItemA(HMENU hMenu, UINT uItem, WINBOOL bypos, - const MENUITEMINFO *lpmiiBuf) -{ - - LPMENUITEMINFO lpmii = lpmiiBuf; - WCHAR MenuTextW[MAX_PATH]; - char *MenuTextA; - WINBOOL bRet; - int i=0; - MenuTextA = lpmii->dwTypeData; - lpmii->dwTypeData = MenuTextW; - while ( MenuTextA[i] != 0 && i < MAX_PATH ) - { - MenuTextW[i] = MenuTextA[i]; - i++; - } - MenuTextW[i] = 0; - lpmii->dwTypeData = (LPWSTR)MenuTextW; - bRet = InsertMenuItemW(hMenu, uItem, bypos, lpmii); - lpmii->dwTypeData = (LPWSTR)MenuTextA; - return bRet; - - -} - - -/********************************************************************** - * InsertMenuItemW - */ -WINBOOL STDCALL InsertMenuItemW(HMENU hMenu, UINT uItem, WINBOOL bypos, - const MENUITEMINFO *lpmii) -{ - return SetMenuItemInfoW(hMenu,uItem,bypos,lpmii); -} - -/********************************************************************** - * CheckMenuRadioItem - */ - -WINBOOL STDCALL CheckMenuRadioItem(HMENU hMenu, - UINT first, UINT last, UINT check, - UINT bypos) -{ - MENUITEM *mifirst, *milast, *micheck; - HMENU mfirst = hMenu, mlast = hMenu, mcheck = hMenu; - - // TRACE(menu, "ox%x: %d-%d, check %d, bypos=%d\n", -// hMenu, first, last, check, bypos); - - mifirst = MENU_FindItem (&mfirst, &first, bypos); - milast = MENU_FindItem (&mlast, &last, bypos); - micheck = MENU_FindItem (&mcheck, &check, bypos); - - if (mifirst == NULL || milast == NULL || micheck == NULL || - mifirst > milast || mfirst != mlast || mfirst != mcheck || - micheck > milast || micheck < mifirst) - return FALSE; - - while (mifirst <= milast) - { - if (mifirst == micheck) - { - mifirst->fType |= MFT_RADIOCHECK; - mifirst->fState |= MFS_CHECKED; - } else { - mifirst->fType &= ~MFT_RADIOCHECK; - mifirst->fState &= ~MFS_CHECKED; - } - mifirst++; - } - - return TRUE; -} - - - -/********************************************************************** - * GetMenuItemRect - */ - -WINBOOL STDCALL GetMenuItemRect (HWND hwnd, HMENU hMenu, UINT uItem, - LPRECT rect) -{ - RECT saverect, clientrect; - WINBOOL barp; - HDC hdc; - WND *wndPtr; - MENUITEM *item; - HMENU orghMenu = hMenu; - - // TRACE(menu, "(0x%x,0x%x,%d,%p)\n", -// hwnd, hMenu, uItem, rect); - - item = MENU_FindItem (&hMenu, &uItem, MF_BYPOSITION); - wndPtr = WIN_FindWndPtr (hwnd); - if (!rect || !item || !wndPtr) return FALSE; - - GetClientRect( hwnd, &clientrect ); - hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW ); - barp = (hMenu == orghMenu); - - saverect = item->rect; - MENU_CalcItemSize (hdc, item, hwnd, - clientrect.left, clientrect.top, barp); - *rect = item->rect; - item->rect = saverect; - - ReleaseDC( hwnd, hdc ); - return TRUE; -} - - - -/********************************************************************** - * SetMenuContextHelpId - */ -WINBOOL STDCALL SetMenuContextHelpId( HMENU hMenu, DWORD dwContextHelpId) -{ - POPUPMENU *pMenu; - - if (!(pMenu = (POPUPMENU *)(hMenu))) - return FALSE; - pMenu->dwContextHelpId = dwContextHelpId; - return TRUE; -} - - - -/********************************************************************** - * GetMenuContextHelpId - */ -DWORD STDCALL GetMenuContextHelpId( HMENU hMenu ) -{ - POPUPMENU *pMenu; - - if (!(pMenu = (POPUPMENU *)(hMenu))) - return -1; - return pMenu->dwContextHelpId; -} - - - - - -/********************************************************************** - * CreatePopupMenu (USER32.82) - */ -HMENU STDCALL CreatePopupMenu(void) -{ - HMENU hmenu; - POPUPMENU *menu; - - if (!(hmenu = CreateMenu())) return 0; - menu = (POPUPMENU *)( hmenu ); - menu->wFlags |= MF_POPUP; - return hmenu; -} - -/********************************************************************** - * TrackPopupMenu (USER32.549) - */ -WINBOOL STDCALL TrackPopupMenu( HMENU hMenu, UINT wFlags, INT x, INT y, - INT nReserved, HWND hWnd, const RECT *lpRect ) -{ - WINBOOL ret = FALSE; - - HideCaret(0); - SendMessageA( hWnd, WM_INITMENUPOPUP, (WPARAM)hMenu, 0); - if (MENU_ShowPopup( hWnd, hMenu, 0, x, y, 0, 0 )) - ret = MENU_TrackMenu( hMenu, wFlags & ~TPM_INTERNAL, 0, 0, hWnd, lpRect ); - ShowCaret(0); - return ret; -} - -/********************************************************************** - * TrackPopupMenuEx (USER32.550) - */ -WINBOOL STDCALL TrackPopupMenuEx( HMENU hMenu, UINT wFlags, INT x, INT y, - HWND hWnd, LPTPMPARAMS lpTpm ) -{ -// FIXME(menu, "not fully implemented\n" ); - return TrackPopupMenu( hMenu, wFlags, x, y, 0, hWnd, - lpTpm ? &lpTpm->rcExclude : NULL ); -} - -/*********************************************************************** - * PopupMenuWndProc - * - * NOTE: Windows has totally different (and undocumented) popup wndproc. - */ -LRESULT STDCALL PopupMenuWndProcA( HWND hwnd, UINT message, WPARAM wParam, - LPARAM lParam ) -{ - WND* wndPtr = WIN_FindWndPtr(hwnd); - - switch(message) - { - case WM_CREATE: - { - CREATESTRUCT *cs = (CREATESTRUCT*)lParam; - SetWindowLong( hwnd, 0, (LONG)cs->lpCreateParams ); - return 0; - } - - case WM_MOUSEACTIVATE: /* We don't want to be activated */ - return MA_NOACTIVATE; - - case WM_PAINT: - { - PAINTSTRUCT ps; - BeginPaint( hwnd, &ps ); - MENU_DrawPopupMenu( hwnd, ps.hdc, (HMENU)GetWindowLong( hwnd, 0 ) ); - EndPaint( hwnd, &ps ); - return 0; - } - case WM_ERASEBKGND: - return 1; - - case WM_DESTROY: - - /* zero out global pointer in case resident popup window - * was somehow destroyed. */ - - if( pTopPopupWnd ) - { - if( hwnd == pTopPopupWnd->hwndSelf ) - { - DPRINT("menu resident popup destroyed!\n"); - - pTopPopupWnd = NULL; - uSubPWndLevel = 0; - } - else - uSubPWndLevel--; - } - break; - - case WM_SHOWWINDOW: - - if( wParam ) - { - if( !(*(HMENU*)wndPtr->wExtra) ) {} - DPRINT("menu no menu to display\n"); - } - else - (LRESULT)*(HMENU*)wndPtr->wExtra = 0; - break; - - case MM_SETMENUHANDLE: - - (LRESULT)*(HMENU*)wndPtr->wExtra = (HMENU)wParam; - break; - - case MM_GETMENUHANDLE: - - return (LRESULT)*(HMENU*)wndPtr->wExtra; - - default: - return (LRESULT)DefWindowProcA( hwnd, message, wParam, lParam ); - } - return (LRESULT)0; -} - -/*********************************************************************** - * PopupMenuWndProc - * - * NOTE: Windows has totally different (and undocumented) popup wndproc. - */ -LRESULT STDCALL PopupMenuWndProcW( HWND hwnd, UINT message, WPARAM wParam, - LPARAM lParam ) -{ - WND* wndPtr = WIN_FindWndPtr(hwnd); - - switch(message) - { - case WM_CREATE: - { - CREATESTRUCT *cs = (CREATESTRUCT*)lParam; - SetWindowLong( hwnd, 0, (LONG)cs->lpCreateParams ); - return 0; - } - - case WM_MOUSEACTIVATE: /* We don't want to be activated */ - return MA_NOACTIVATE; - - case WM_PAINT: - { - PAINTSTRUCT ps; - BeginPaint( hwnd, &ps ); - MENU_DrawPopupMenu( hwnd, ps.hdc, (HMENU)GetWindowLong( hwnd, 0 ) ); - EndPaint( hwnd, &ps ); - return 0; - } - case WM_ERASEBKGND: - return 1; - - case WM_DESTROY: - - /* zero out global pointer in case resident popup window - * was somehow destroyed. */ - - if( pTopPopupWnd ) - { - if( hwnd == pTopPopupWnd->hwndSelf ) - { - DPRINT("menu resident popup destroyed!\n"); - - pTopPopupWnd = NULL; - uSubPWndLevel = 0; - } - else - uSubPWndLevel--; - } - break; - - case WM_SHOWWINDOW: - - if( wParam ) - { - if( !(*(HMENU*)wndPtr->wExtra) ) - DPRINT("menu no menu to display\n"); - } - else - (LRESULT)*(HMENU*)wndPtr->wExtra = 0; - break; - - case MM_SETMENUHANDLE: - - (LRESULT)*(HMENU*)wndPtr->wExtra = (HMENU)wParam; - break; - - case MM_GETMENUHANDLE: - - return (LRESULT)*(HMENU*)wndPtr->wExtra; - - default: - return (LRESULT)DefWindowProcW( hwnd, message, wParam, lParam ); - } - return (LRESULT)0; -} - - - - -/******************************************************************* - * ChangeMenuA (USER32.23) - */ -WINBOOL STDCALL ChangeMenuA( HMENU hMenu, UINT pos, LPCSTR data, - UINT id, UINT flags ) -{ - //DPRINT("menu menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n", - // hMenu, pos, (DWORD)data, id, flags ); - if (flags & MF_APPEND) return AppendMenuA( hMenu, flags & ~MF_APPEND, - id, data ); - if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE); - if (flags & MF_CHANGE) return ModifyMenuA(hMenu, pos, flags & ~MF_CHANGE, - id, data ); - if (flags & MF_REMOVE) return RemoveMenu( hMenu, - flags & MF_BYPOSITION ? pos : id, - flags & ~MF_REMOVE ); - /* Default: MF_INSERT */ - return InsertMenuA( hMenu, pos, flags, id, data ); -} - - -/******************************************************************* - * ChangeMenuW (USER32.24) - */ -WINBOOL STDCALL ChangeMenuW( HMENU hMenu, UINT pos, LPCWSTR data, - UINT id, UINT flags ) -{ - //DPRINT("menu menu=%08x pos=%d data=%08lx id=%08x flags=%08x\n", - // hMenu, pos, (DWORD)data, id, flags ); - if (flags & MF_APPEND) return AppendMenuW( hMenu, flags & ~MF_APPEND, - id, data ); - if (flags & MF_DELETE) return DeleteMenu(hMenu, pos, flags & ~MF_DELETE); - if (flags & MF_CHANGE) return ModifyMenuW(hMenu, pos, flags & ~MF_CHANGE, - id, data ); - if (flags & MF_REMOVE) return RemoveMenu( hMenu, - flags & MF_BYPOSITION ? pos : id, - flags & ~MF_REMOVE ); - /* Default: MF_INSERT */ - return InsertMenuW( hMenu, pos, flags, id, data ); -} - -/******************************************************************* - * CheckMenuItem (USER32.46) - */ -DWORD STDCALL CheckMenuItem( HMENU hMenu, UINT id, UINT flags ) -{ - MENUITEM *item; - DWORD ret; - - DPRINT("menu %04x %04x %04x\n", (UINT)hMenu, id, flags ); - - if (!(item = MENU_FindItem( &hMenu, &id, flags ))) return -1; - ret = item->fState & MF_CHECKED; - if (flags & MF_CHECKED) item->fState |= MF_CHECKED; - else item->fState &= ~MF_CHECKED; - return ret; -} - - -/********************************************************************** - * EnableMenuItem (USER32.170) - */ -WINBOOL -STDCALL -EnableMenuItem( - HMENU hMenu, - UINT uIDEnableItem, - UINT uEnable) -{ - UINT oldflags; - MENUITEM *item; - - DPRINT("menu (%04x, %04X, %04X) !\n", (UINT) hMenu, uIDEnableItem, uEnable); - - if (!(item = MENU_FindItem( &hMenu, &uIDEnableItem, uEnable ))) - return (UINT)-1; - - oldflags = item->fState & (MF_GRAYED | MF_DISABLED); - item->fState ^= (oldflags ^ uEnable) & (MF_GRAYED | MF_DISABLED); - return oldflags; -} - -/******************************************************************* - * GetMenuStringA (USER32.268) - */ -INT STDCALL GetMenuStringA( HMENU hMenu, UINT wItemID, - LPSTR str, INT nMaxSiz, UINT wFlags ) -{ - MENUITEM *item; - int i; - int len; - DPRINT( "menu=%04x item=%04x ptr=%p len=%d flags=%04x\n", hMenu, wItemID, str, nMaxSiz, wFlags ); - if (!str || !nMaxSiz) - return 0; - str[0] = '\0'; - - if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) - return 0; - if (!IS_STRING_ITEM(item->fType)) return 0; - - len = min(lstrlenW(item->text),nMaxSiz-1); - for(i=0;itext[i]; - - return len; -} - - -/******************************************************************* - * GetMenuStringW (USER32.269) - */ -INT STDCALL GetMenuStringW( HMENU hMenu, UINT wItemID, - LPWSTR str, INT nMaxSiz, UINT wFlags ) -{ - MENUITEM *item; - - DPRINT( "menu=%04x item=%04x ptr=%p len=%d flags=%04x\n", hMenu, wItemID, str, nMaxSiz, wFlags ); - if (!str || !nMaxSiz) - return 0; - str[0] = '\0'; - if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) - return 0; - lstrcpynW( str, item->text, nMaxSiz ); - return lstrlenW(str); -} - -/********************************************************************** - * HiliteMenuItem (USER32.318) - */ -WINBOOL STDCALL HiliteMenuItem( HWND hWnd, HMENU hMenu, UINT wItemID, - UINT wHilite ) -{ - LPPOPUPMENU menu; - DPRINT("menu (%04x, %04x, %04x, %04x);\n", hWnd, hMenu, wItemID, wHilite); - - if (!MENU_FindItem( &hMenu, &wItemID, wHilite )) return FALSE; - if (!(menu = (LPPOPUPMENU) (hMenu))) return FALSE; - if (menu->FocusedItem == wItemID) return TRUE; - MENU_HideSubPopups( hWnd, hMenu, FALSE ); - MENU_SelectItem( hWnd, hMenu, wItemID, TRUE ); - return TRUE; -} - -/********************************************************************** - * GetMenuState (USER32.267) - */ -UINT STDCALL GetMenuState( HMENU hMenu, UINT wItemID, UINT wFlags ) -{ - MENUITEM *item; - DPRINT("menu (%04x, %04x, %04x);\n", (UINT)hMenu, wItemID, wFlags); - if (!(item = MENU_FindItem( &hMenu, &wItemID, wFlags ))) return -1; - //debug_print_menuitem (" item: ", item, ""); - if (item->fType & MF_POPUP) - { - POPUPMENU *menu = (POPUPMENU *)( item->hSubMenu ); - if (!menu) return -1; - else return (menu->nItems << 8) | ((item->fState|item->fType) & 0xff); - } - else - { - /* We used to (from way back then) mask the result to 0xff. */ - /* I don't know why and it seems wrong as the documented */ - /* return flag MF_SEPARATOR is outside that mask. */ - return (item->fType | item->fState); - } -} - -/********************************************************************** - * GetMenuItemCount (USER32.262) - */ -INT STDCALL GetMenuItemCount( HMENU hMenu ) -{ - LPPOPUPMENU menu = (LPPOPUPMENU)(hMenu); - if (!IS_A_MENU(menu)) return -1; - DPRINT("menu (%04x) returning %d\n", (UINT)hMenu, menu->nItems ); - return menu->nItems; -} - -/********************************************************************** - * GetMenuItemID (USER32.263) - */ -UINT STDCALL GetMenuItemID( HMENU hMenu, INT nPos ) -{ - LPPOPUPMENU menu; - - if (!(menu = (LPPOPUPMENU)(hMenu))) return -1; - if ((nPos < 0) || (nPos >= menu->nItems)) return -1; - if (menu->items[nPos].fType & MF_POPUP) return -1; - return menu->items[nPos].wID; -} - - - - -/******************************************************************* - * InsertMenuA (USER32.2) - */ -WINBOOL STDCALL InsertMenuA( HMENU hMenu, UINT pos, UINT flags, - UINT id, LPCSTR str ) -{ - int i; - WCHAR MenuTextW[MAX_PATH]; - i = 0; - while ((*str)!=0 && i < MAX_PATH) - { - MenuTextW[i] = *str; - str++; - i++; - } - MenuTextW[i] = 0; - return InsertMenuW(hMenu,pos,flags,id,MenuTextW); - - -} - - -/******************************************************************* - * InsertMenuW (USER32.5) - */ -WINBOOL STDCALL InsertMenuW( HMENU hMenu, UINT pos, UINT flags, - UINT id, LPCWSTR str ) -{ - MENUITEM *item; - - - if (!(item = MENU_InsertItem( hMenu, pos, flags ))) return FALSE; - - - - if (!(MENU_SetItemData( item, flags, id, str ))) - { - RemoveMenu( hMenu, pos, flags ); - return FALSE; - } - - if (flags & MF_POPUP) /* Set the MF_POPUP flag on the popup-menu */ - ((POPUPMENU *)((HMENU)id))->wFlags |= MF_POPUP; - - item->hCheckBit = item->hUnCheckBit = 0; - return TRUE; -} - - - - -/******************************************************************* - * AppendMenuA (USER32.5) - */ -WINBOOL STDCALL AppendMenuA( HMENU hMenu, UINT flags, - UINT id, LPCSTR data ) -{ - return InsertMenuA( hMenu, -1, flags | MF_BYPOSITION, id, data ); -} - - -/******************************************************************* - * AppendMenuW (USER32.6) - */ -WINBOOL STDCALL AppendMenuW( HMENU hMenu, UINT flags, - UINT id, LPCWSTR data ) -{ - return InsertMenuW( hMenu, -1, flags | MF_BYPOSITION, id, data ); -} - - - - -/********************************************************************** - * RemoveMenu (USER32.441) - */ -WINBOOL STDCALL RemoveMenu( HMENU hMenu, UINT nPos, UINT wFlags ) -{ - LPPOPUPMENU menu; - MENUITEM *item; - - DPRINT("menu (%04x, %04x, %04x)\n",(UINT)hMenu, nPos, wFlags); - if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE; - if (!(menu = (LPPOPUPMENU) (hMenu))) return FALSE; - - /* Remove item */ - - MENU_FreeItemData( item ); - - if (--menu->nItems == 0) - { - HeapFree( GetProcessHeap(), 0, menu->items ); - menu->items = NULL; - } - else - { - while(nPos < menu->nItems) - { - *item = *(item+1); - item++; - nPos++; - } - menu->items = HeapReAlloc( GetProcessHeap(), 0, menu->items, - menu->nItems * sizeof(MENUITEM) ); - } - return TRUE; -} - - -/********************************************************************** - * DeleteMenu (USER32.129) - */ -WINBOOL STDCALL DeleteMenu( HMENU hMenu, UINT nPos, UINT wFlags ) -{ - MENUITEM *item = MENU_FindItem( &hMenu, &nPos, wFlags ); - if (!item) - return FALSE; - if (item->fType & MF_POPUP) - DestroyMenu( item->hSubMenu ); - /* nPos is now the position of the item */ - RemoveMenu( hMenu, nPos, wFlags | MF_BYPOSITION ); - return TRUE; -} - - - - -/******************************************************************* - * ModifyMenuA (USER32.397) - */ -WINBOOL STDCALL ModifyMenuA( HMENU hMenu, UINT pos, UINT flags, - UINT id, LPCSTR str ) -{ - int i; - WCHAR MenuTextW[MAX_PATH]; - i = 0; - while ((*str)!=0 && i < MAX_PATH) - { - MenuTextW[i] = *str; - str++; - i++; - } - MenuTextW[i] = 0; - return ModifyMenuW(hMenu,pos,flags,id,MenuTextW); -} - - -/******************************************************************* - * ModifyMenuW (USER32.398) - */ -WINBOOL -STDCALL -ModifyMenuW(HMENU hMnu,UINT uPosition, - UINT uFlags, UINT uIDNewItem, - LPCWSTR lpNewItem ) -{ - MENUITEM *mnItem; - - - if (!(mnItem = MENU_FindItem( &hMnu, &uPosition, uFlags ))) - return FALSE; - return MENU_SetItemData( mnItem, uFlags, uIDNewItem, lpNewItem ); -} - - - - - - - -/********************************************************************** - * GetMenuCheckMarkDimensions (USER32.258) - */ -LONG -STDCALL -GetMenuCheckMarkDimensions(VOID) -{ - - return MAKELONG(GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK) ); -} - - - - - -/********************************************************************** - * SetMenuItemBitmaps (USER32.490) - */ -WINBOOL STDCALL SetMenuItemBitmaps( HMENU hMenu, UINT nPos, UINT wFlags, - HBITMAP hNewUnCheck, HBITMAP hNewCheck) -{ - MENUITEM *item; - DPRINT("menu (%04x, %04x, %04x, %04x, %04x)\n", - (UINT)hMenu, nPos, wFlags, (UINT)hNewCheck, (UINT)hNewUnCheck); - if (!(item = MENU_FindItem( &hMenu, &nPos, wFlags ))) return FALSE; - - if (!hNewCheck && !hNewUnCheck) - { - item->fState &= ~MF_USECHECKBITMAPS; - } - else /* Install new bitmaps */ - { - item->hCheckBit = hNewCheck; - item->hUnCheckBit = hNewUnCheck; - item->fState |= MF_USECHECKBITMAPS; - } - return TRUE; -} - - - - diff --git a/reactos/lib/user32/controls/scroll.c b/reactos/lib/user32/controls/scroll.c deleted file mode 100644 index ca5c40d0ee6..00000000000 --- a/reactos/lib/user32/controls/scroll.c +++ /dev/null @@ -1,1446 +0,0 @@ -/* - * Scrollbar control - * - * Copyright 1993 Martin Ayotte - * Copyright 1994, 1996 Alexandre Julliard - */ - -#include -#define MAX max -#define MIN min - -#include -#include -#include -#include -#include -#include -#include - -static HBITMAP hUpArrow = 0; -static HBITMAP hDnArrow = 0; -static HBITMAP hLfArrow = 0; -static HBITMAP hRgArrow = 0; -static HBITMAP hUpArrowD = 0; -static HBITMAP hDnArrowD = 0; -static HBITMAP hLfArrowD = 0; -static HBITMAP hRgArrowD = 0; -static HBITMAP hUpArrowI = 0; -static HBITMAP hDnArrowI = 0; -static HBITMAP hLfArrowI = 0; -static HBITMAP hRgArrowI = 0; - -#define TOP_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow)) -#define BOTTOM_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow)) -#define LEFT_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow)) -#define RIGHT_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow)) - - - /* Minimum size of the rectangle between the arrows */ -#define SCROLL_MIN_RECT 4 - - /* Minimum size of the thumb in pixels */ -#define SCROLL_MIN_THUMB 6 - - /* Overlap between arrows and thumb */ -#define SCROLL_ARROW_THUMB_OVERLAP 1 - - /* Delay (in ms) before first repetition when holding the button down */ -#define SCROLL_FIRST_DELAY 200 - - /* Delay (in ms) between scroll repetitions */ -#define SCROLL_REPEAT_DELAY 50 - - /* Scroll timer id */ -#define SCROLL_TIMER 0 - - /* Scroll-bar hit testing */ -enum SCROLL_HITTEST -{ - SCROLL_NOWHERE, /* Outside the scroll bar */ - SCROLL_TOP_ARROW, /* Top or left arrow */ - SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */ - SCROLL_THUMB, /* Thumb rectangle */ - SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */ - SCROLL_BOTTOM_ARROW /* Bottom or right arrow */ -}; - - /* What to do after SCROLL_SetScrollInfo() */ -#define SA_SSI_HIDE 0x0001 -#define SA_SSI_SHOW 0x0002 -#define SA_SSI_REFRESH 0x0004 -#define SA_SSI_REPAINT_ARROWS 0x0008 - - /* Thumb-tracking info */ -static HWND SCROLL_TrackingWin = 0; -static INT SCROLL_TrackingBar = 0; -static INT SCROLL_TrackingPos = 0; -static INT SCROLL_TrackingVal = 0; - /* Hit test code of the last button-down event */ -static enum SCROLL_HITTEST SCROLL_trackHitTest; -static BOOL SCROLL_trackVertical; - - /* Is the moving thumb being displayed? */ -static BOOL SCROLL_MovingThumb = FALSE; - - /* Local functions */ -static BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, - BOOL fShowH, BOOL fShowV ); -static INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, - const SCROLLINFO *info, INT *action ); - -/*********************************************************************** - * SCROLL_LoadBitmaps - */ -static void SCROLL_LoadBitmaps(void) -{ - hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_UPARROW) ); - hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_DNARROW) ); - hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_LFARROW) ); - hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_RGARROW) ); - hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_UPARROWD) ); - hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_DNARROWD) ); - hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_LFARROWD) ); - hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_RGARROWD) ); - hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_UPARROWI) ); - hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_DNARROWI) ); - hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_LFARROWI) ); - hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCE(OBM_RGARROWI) ); -} - - -/*********************************************************************** - * SCROLL_GetPtrScrollInfo - */ -static SCROLLBAR_INFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, INT nBar ) -{ - SCROLLBAR_INFO *infoPtr; - - if (!wndPtr) return NULL; - switch(nBar) - { - case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break; - case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break; - case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break; - default: return NULL; - } - - if (!infoPtr) /* Create the info structure if needed */ - { - if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) ))) - { - infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0; - infoPtr->MaxVal = 100; - infoPtr->flags = ESB_ENABLE_BOTH; - if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr; - else wndPtr->pVScroll = infoPtr; - } - if (!hUpArrow) SCROLL_LoadBitmaps(); - } - return infoPtr; -} - - -/*********************************************************************** - * SCROLL_GetScrollInfo - */ -static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - return SCROLL_GetPtrScrollInfo( wndPtr, nBar ); -} - - -/*********************************************************************** - * SCROLL_GetScrollBarRect - * - * Compute the scroll bar rectangle, in drawing coordinates (i.e. client - * coords for SB_CTL, window coords for SB_VERT and SB_HORZ). - * 'arrowSize' returns the width or height of an arrow (depending on - * the orientation of the scrollbar), 'thumbSize' returns the size of - * the thumb, and 'thumbPos' returns the position of the thumb - * relative to the left or to the top. - * Return TRUE if the scrollbar is vertical, FALSE if horizontal. - */ -static BOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect, - INT *arrowSize, INT *thumbSize, - INT *thumbPos ) -{ - INT pixels; - BOOL vertical; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - switch(nBar) - { - case SB_HORZ: - lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left; - lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top; - lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left; - lprect->bottom = lprect->top + SYSMETRICS_CYHSCROLL; - if(wndPtr->dwStyle & WS_BORDER) { - lprect->left--; - lprect->right++; - } else if(wndPtr->dwStyle & WS_VSCROLL) - lprect->right++; - vertical = FALSE; - break; - - case SB_VERT: - lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left; - lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top; - lprect->right = lprect->left + SYSMETRICS_CXVSCROLL; - lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top; - if(wndPtr->dwStyle & WS_BORDER) { - lprect->top--; - lprect->bottom++; - } else if(wndPtr->dwStyle & WS_HSCROLL) - lprect->bottom++; - vertical = TRUE; - break; - - case SB_CTL: - GetClientRect( hwnd, lprect ); - vertical = ((wndPtr->dwStyle & SBS_VERT) != 0); - break; - - default: - return FALSE; - } - - if (vertical) pixels = lprect->bottom - lprect->top; - else pixels = lprect->right - lprect->left; - - if (pixels <= 2*SYSMETRICS_CXVSCROLL + SCROLL_MIN_RECT) - { - if (pixels > SCROLL_MIN_RECT) - *arrowSize = (pixels - SCROLL_MIN_RECT) / 2; - else - *arrowSize = 0; - *thumbPos = *thumbSize = 0; - } - else - { - SCROLLBAR_INFO *info = SCROLL_GetPtrScrollInfo( wndPtr, nBar ); - - *arrowSize = SYSMETRICS_CXVSCROLL; - pixels -= (2 * (SYSMETRICS_CXVSCROLL - SCROLL_ARROW_THUMB_OVERLAP)); - - if (info->Page) - { - *thumbSize = pixels * info->Page / (info->MaxVal-info->MinVal+1); - if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB; - } - else *thumbSize = SYSMETRICS_CXVSCROLL; - - if (((pixels -= *thumbSize ) < 0) || - ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)) - { - /* Rectangle too small or scrollbar disabled -> no thumb */ - *thumbPos = *thumbSize = 0; - } - else - { - INT max = info->MaxVal - MAX( info->Page-1, 0 ); - if (info->MinVal >= max) - *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - else - *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP - + pixels * (info->CurVal-info->MinVal) / (max - info->MinVal); - } - } - return vertical; -} - - -/*********************************************************************** - * SCROLL_GetThumbVal - * - * Compute the current scroll position based on the thumb position in pixels - * from the top of the scroll-bar. - */ -static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect, - BOOL vertical, INT pos ) -{ - INT thumbSize; - INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left; - - if ((pixels -= 2*(SYSMETRICS_CXVSCROLL - SCROLL_ARROW_THUMB_OVERLAP)) <= 0) - return infoPtr->MinVal; - - if (infoPtr->Page) - { - thumbSize = pixels * infoPtr->Page/(infoPtr->MaxVal-infoPtr->MinVal+1); - if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB; - } - else thumbSize = SYSMETRICS_CXVSCROLL; - - if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal; - - pos = MAX( 0, pos - (SYSMETRICS_CXVSCROLL - SCROLL_ARROW_THUMB_OVERLAP) ); - if (pos > pixels) pos = pixels; - - if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal; - else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1; - return infoPtr->MinVal + ((pos + pixels / 2) / pixels); -} - -/*********************************************************************** - * SCROLL_PtInRectEx - */ -static BOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, BOOL vertical ) -{ - RECT rect = *lpRect; - - if (vertical) - { - rect.left -= lpRect->right - lpRect->left; - rect.right += lpRect->right - lpRect->left; - } - else - { - rect.top -= lpRect->bottom - lpRect->top; - rect.bottom += lpRect->bottom - lpRect->top; - } - return PtInRect( &rect, pt ); -} - -/*********************************************************************** - * SCROLL_ClipPos - */ -static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt ) -{ - if( pt.x < lpRect->left ) - pt.x = lpRect->left; - else - if( pt.x > lpRect->right ) - pt.x = lpRect->right; - - if( pt.y < lpRect->top ) - pt.y = lpRect->top; - else - if( pt.y > lpRect->bottom ) - pt.y = lpRect->bottom; - - return pt; -} - - -/*********************************************************************** - * SCROLL_HitTest - * - * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!). - */ -static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar, - POINT pt, BOOL bDragging ) -{ - INT arrowSize, thumbSize, thumbPos; - RECT rect; - - BOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, - &arrowSize, &thumbSize, &thumbPos ); - - if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) || - (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE; - - if (vertical) - { - if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW; - if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW; - if (!thumbPos) return SCROLL_TOP_RECT; - pt.y -= rect.top; - if (pt.y < thumbPos) return SCROLL_TOP_RECT; - if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT; - } - else /* horizontal */ - { - if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW; - if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW; - if (!thumbPos) return SCROLL_TOP_RECT; - pt.x -= rect.left; - if (pt.x < thumbPos) return SCROLL_TOP_RECT; - if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT; - } - return SCROLL_THUMB; -} - - -/*********************************************************************** - * SCROLL_DrawArrows - * - * Draw the scroll bar arrows. - */ -static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr, - RECT *rect, INT arrowSize, BOOL vertical, - BOOL top_pressed, BOOL bottom_pressed ) -{ - HDC hdcMem = CreateCompatibleDC( hdc ); - HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ? - TOP_ARROW(infoPtr->flags, top_pressed) - : LEFT_ARROW(infoPtr->flags, top_pressed)); - - SetStretchBltMode( hdc, STRETCH_DELETESCANS ); - StretchBlt( hdc, rect->left, rect->top, - vertical ? rect->right-rect->left : arrowSize, - vertical ? arrowSize : rect->bottom-rect->top, - hdcMem, 0, 0, - SYSMETRICS_CXVSCROLL, SYSMETRICS_CYHSCROLL, - SRCCOPY ); - - SelectObject( hdcMem, vertical ? - BOTTOM_ARROW( infoPtr->flags, bottom_pressed ) - : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) ); - if (vertical) - StretchBlt( hdc, rect->left, rect->bottom - arrowSize, - rect->right - rect->left, arrowSize, - hdcMem, 0, 0, - SYSMETRICS_CXVSCROLL, SYSMETRICS_CYHSCROLL, - SRCCOPY ); - else - StretchBlt( hdc, rect->right - arrowSize, rect->top, - arrowSize, rect->bottom - rect->top, - hdcMem, 0, 0, - SYSMETRICS_CXVSCROLL, SYSMETRICS_CYHSCROLL, - SRCCOPY ); - SelectObject( hdcMem, hbmpPrev ); - DeleteDC( hdcMem ); -} - - -/*********************************************************************** - * SCROLL_DrawMovingThumb - * - * Draw the moving thumb rectangle. - */ -static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, BOOL vertical, - INT arrowSize, INT thumbSize ) -{ - RECT r = *rect; - if (vertical) - { - r.top += SCROLL_TrackingPos; - if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - if (r.top + thumbSize > - rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)) - r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - - thumbSize; - r.bottom = r.top + thumbSize; - } - else - { - r.left += SCROLL_TrackingPos; - if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - if (r.left + thumbSize > - rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)) - r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - - thumbSize; - r.right = r.left + thumbSize; - } - DrawFocusRect( hdc, &r ); - SCROLL_MovingThumb = !SCROLL_MovingThumb; -} - - -/*********************************************************************** - * SCROLL_DrawInterior - * - * Draw the scroll bar interior (everything except the arrows). - */ -static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar, - RECT *rect, INT arrowSize, - INT thumbSize, INT thumbPos, - UINT flags, BOOL vertical, - BOOL top_selected, BOOL bottom_selected ) -{ - RECT r; - - /* Select the correct brush and pen */ - - SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) ); - if ((flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH) - { - /* This ought to be the color of the parent window */ - SelectObject( hdc, GetSysColorBrush(COLOR_WINDOW) ); - } - else - { - if (nBar == SB_CTL) /* Only scrollbar controls send WM_CTLCOLOR */ - { - HBRUSH hbrush = SendMessageA(GetParent(hwnd), - WM_CTLCOLORSCROLLBAR, hdc, hwnd ); - SelectObject( hdc, hbrush ); - } - else SelectObject( hdc, GetSysColorBrush(COLOR_SCROLLBAR) ); - } - - /* Calculate the scroll rectangle */ - - r = *rect; - if (vertical) - { - r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - } - else - { - r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - } - - /* Draw the scroll bar frame */ - - Rectangle( hdc, r.left, r.top, r.right, r.bottom ); - - /* Draw the scroll rectangles and thumb */ - - if (!thumbPos) /* No thumb to draw */ - { - PatBlt( hdc, r.left+1, r.top+1, r.right - r.left - 2, - r.bottom - r.top - 2, PATCOPY ); - return; - } - - if (vertical) - { - PatBlt( hdc, r.left + 1, r.top + 1, - r.right - r.left - 2, - thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - 1, - top_selected ? 0x0f0000 : PATCOPY ); - r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - PatBlt( hdc, r.left + 1, r.top + thumbSize, - r.right - r.left - 2, - r.bottom - r.top - thumbSize - 1, - bottom_selected ? 0x0f0000 : PATCOPY ); - r.bottom = r.top + thumbSize; - } - else /* horizontal */ - { - PatBlt( hdc, r.left + 1, r.top + 1, - thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - 1, - r.bottom - r.top - 2, - top_selected ? 0x0f0000 : PATCOPY ); - r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - PatBlt( hdc, r.left + thumbSize, r.top + 1, - r.right - r.left - thumbSize - 1, - r.bottom - r.top - 2, - bottom_selected ? 0x0f0000 : PATCOPY ); - r.right = r.left + thumbSize; - } - - /* Draw the thumb */ - - SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) ); - Rectangle( hdc, r.left, r.top, r.right, r.bottom ); - r.top++, r.left++; - DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT ); - if (SCROLL_MovingThumb && - (SCROLL_TrackingWin == hwnd) && - (SCROLL_TrackingBar == nBar)) - { - SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize ); - SCROLL_MovingThumb = TRUE; - } -} - - -/*********************************************************************** - * SCROLL_DrawScrollBar - * - * Redraw the whole scrollbar. - */ -void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar, - BOOL arrows, BOOL interior ) -{ - INT arrowSize, thumbSize, thumbPos; - RECT rect; - BOOL vertical; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - SCROLLBAR_INFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar ); - - if (!wndPtr || !infoPtr || - ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) || - ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) return; - if (!WIN_IsWindowDrawable( wndPtr, FALSE )) return; - - vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, - &arrowSize, &thumbSize, &thumbPos ); - - /* Draw the arrows */ - - if (arrows && arrowSize) - { - if( vertical == SCROLL_trackVertical && GetCapture() == hwnd ) - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - (SCROLL_trackHitTest == SCROLL_TOP_ARROW), - (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) ); - else - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - FALSE, FALSE ); - } - if( interior ) - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, FALSE, FALSE ); -} - - -/*********************************************************************** - * SCROLL_RefreshScrollBar - * - * Repaint the scroll bar interior after a SetScrollRange() or - * SetScrollPos() call. - */ -static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar, - BOOL arrows, BOOL interior ) -{ - HDC hdc = GetDCEx( hwnd, 0, - DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) ); - if (!hdc) return; - - SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior ); - ReleaseDC( hwnd, hdc ); -} - - -/*********************************************************************** - * SCROLL_HandleKbdEvent - * - * Handle a keyboard event (only for SB_CTL scrollbars). - */ -static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - WPARAM msg; - - switch(wParam) - { - case VK_PRIOR: msg = SB_PAGEUP; break; - case VK_NEXT: msg = SB_PAGEDOWN; break; - case VK_HOME: msg = SB_TOP; break; - case VK_END: msg = SB_BOTTOM; break; - case VK_UP: msg = SB_LINEUP; break; - case VK_DOWN: msg = SB_LINEDOWN; break; - default: - return; - } - SendMessageA( GetParent(hwnd), - (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL, - msg, hwnd ); -} - - -/*********************************************************************** - * SCROLL_HandleScrollEvent - * - * Handle a mouse or timer event for the scrollbar. - * 'pt' is the location of the mouse event in client (for SB_CTL) or - * windows coordinates. - */ -void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt) -{ - /* Previous mouse position for timer events */ - static POINT prevPt; - /* Thumb position when tracking started. */ - static UINT trackThumbPos; - /* Position in the scroll-bar of the last button-down event. */ - static INT lastClickPos; - /* Position in the scroll-bar of the last mouse event. */ - static INT lastMousePos; - - enum SCROLL_HITTEST hittest; - HWND hwndOwner, hwndCtl; - BOOL vertical; - INT arrowSize, thumbSize, thumbPos; - RECT rect; - HDC hdc; - - SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ); - if (!infoPtr) return; - if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN)) - return; - - hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW)); - vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, - &arrowSize, &thumbSize, &thumbPos ); - hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd; - hwndCtl = (nBar == SB_CTL) ? hwnd : 0; - - switch(msg) - { - case WM_LBUTTONDOWN: /* Initialise mouse tracking */ - SCROLL_trackVertical = vertical; - SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE ); - lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left); - lastMousePos = lastClickPos; - trackThumbPos = thumbPos; - prevPt = pt; - SetCapture( hwnd ); - if (nBar == SB_CTL) SetFocus( hwnd ); - break; - - case WM_MOUSEMOVE: - hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE ); - prevPt = pt; - break; - - case WM_LBUTTONUP: - hittest = SCROLL_NOWHERE; - ReleaseCapture(); - break; - - case WM_TIMER: - pt = prevPt; - hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE ); - break; - - default: - return; /* Should never happen */ - } - - DPRINT( "Event: hwnd=%04x bar=%d msg=%x pt=%d,%d hit=%d\n", - hwnd, nBar, msg, pt.x, pt.y, hittest ); - - switch(SCROLL_trackHitTest) - { - case SCROLL_NOWHERE: /* No tracking in progress */ - break; - - case SCROLL_TOP_ARROW: - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - (hittest == SCROLL_trackHitTest), FALSE ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_TIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_LINEUP, hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - - case SCROLL_TOP_RECT: - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, - (hittest == SCROLL_trackHitTest), FALSE ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_TIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_PAGEUP, hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - - case SCROLL_THUMB: - if (msg == WM_LBUTTONDOWN) - { - SCROLL_TrackingWin = hwnd; - SCROLL_TrackingBar = nBar; - SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos; - SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize); - } - else if (msg == WM_LBUTTONUP) - { - SCROLL_TrackingWin = 0; - SCROLL_MovingThumb = FALSE; - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, - FALSE, FALSE ); - } - else /* WM_MOUSEMOVE */ - { - UINT pos; - - if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos; - else - { - pt = SCROLL_ClipPos( &rect, pt ); - pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left); - } - if (pos != lastMousePos) - { - SCROLL_DrawMovingThumb( hdc, &rect, vertical, - arrowSize, thumbSize ); - lastMousePos = pos; - SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos; - SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect, - vertical, - SCROLL_TrackingPos ); - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal), - hwndCtl ); - SCROLL_DrawMovingThumb( hdc, &rect, vertical, - arrowSize, thumbSize ); - } - } - break; - - case SCROLL_BOTTOM_RECT: - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, - FALSE, (hittest == SCROLL_trackHitTest) ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_TIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_PAGEDOWN, hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - - case SCROLL_BOTTOM_ARROW: - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - FALSE, (hittest == SCROLL_trackHitTest) ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_TIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_LINEDOWN, (LPARAM)hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - } - - if (msg == WM_LBUTTONUP) - { - hittest = SCROLL_trackHitTest; - SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */ - - if (hittest == SCROLL_THUMB) - { - UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical, - trackThumbPos + lastMousePos - lastClickPos ); - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl ); - } - else - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_ENDSCROLL, (LPARAM)hwndCtl ); - } - - ReleaseDC( hwnd, hdc ); -} - - -/*********************************************************************** - * ScrollBarWndProc - */ -LRESULT STDCALL ScrollBarWndProc( HWND hwnd, UINT message, WPARAM wParam, - LPARAM lParam ) -{ - POINT *pt; - switch(message) - { - case WM_CREATE: - { - CREATESTRUCT *lpCreat = (CREATESTRUCT *)lParam; - if (lpCreat->style & SBS_SIZEBOX) - { - DPRINT( "FIXME Unimplemented style SBS_SIZEBOX.\n" ); - return 0; - } - - if (lpCreat->style & SBS_VERT) - { - if (lpCreat->style & SBS_LEFTALIGN) - MoveWindow( hwnd, lpCreat->x, lpCreat->y, - SYSMETRICS_CXVSCROLL+1, lpCreat->cy, FALSE ); - else if (lpCreat->style & SBS_RIGHTALIGN) - MoveWindow( hwnd, - lpCreat->x+lpCreat->cx-SYSMETRICS_CXVSCROLL-1, - lpCreat->y, - SYSMETRICS_CXVSCROLL+1, lpCreat->cy, FALSE ); - } - else /* SBS_HORZ */ - { - if (lpCreat->style & SBS_TOPALIGN) - MoveWindow( hwnd, lpCreat->x, lpCreat->y, - lpCreat->cx, SYSMETRICS_CYHSCROLL+1, FALSE ); - else if (lpCreat->style & SBS_BOTTOMALIGN) - MoveWindow( hwnd, - lpCreat->x, - lpCreat->y+lpCreat->cy-SYSMETRICS_CYHSCROLL-1, - lpCreat->cx, SYSMETRICS_CYHSCROLL+1, FALSE ); - } - } - if (!hUpArrow) SCROLL_LoadBitmaps(); - DPRINT( "ScrollBar creation, hwnd=%04x\n", hwnd ); - return 0; - - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MOUSEMOVE: - case WM_TIMER: - pt = (POINT *)&lParam; - SCROLL_HandleScrollEvent( hwnd, SB_CTL, message,*pt ); - break; - - case WM_KEYDOWN: - SCROLL_HandleKbdEvent( hwnd, wParam ); - break; - - case WM_ERASEBKGND: - return 1; - - case WM_GETDLGCODE: - return DLGC_WANTARROWS; /* Windows returns this value */ - - case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc = BeginPaint( hwnd, &ps ); - SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE ); - EndPaint( hwnd, &ps ); - } - break; - - - case SBM_SETPOS: - return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam ); - - - case SBM_GETPOS: - return GetScrollPos( hwnd, SB_CTL ); - - - case SBM_SETRANGE: - SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE ); - return 0; /* FIXME: return previous position */ - - - - case SBM_GETRANGE: - GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam ); - return 0; - - - case SBM_ENABLE_ARROWS: - return EnableScrollBar( hwnd, SB_CTL, wParam ); - - case SBM_SETRANGEREDRAW: - SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE ); - return 0; /* FIXME: return previous position */ - - case SBM_SETSCROLLINFO: - return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam ); - - case SBM_GETSCROLLINFO: - return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam ); - - case 0x00e5: - case 0x00e7: - case 0x00e8: - case 0x00eb: - case 0x00ec: - case 0x00ed: - case 0x00ee: - case 0x00ef: - DPRINT( "unknown Win msg %04x wp=%08x lp=%08lx\n", - message, wParam, lParam ); - break; - - default: - if (message >= WM_USER) - DPRINT( "unknown msg %04x wp=%04x lp=%08lx\n", - message, wParam, lParam ); - return DefWindowProcA( hwnd, message, wParam, lParam ); - } - return 0; -} - - - - - -/************************************************************************* - * SetScrollInfo (USER.501) - * SetScrollInfo can be used to set the position, upper bound, - * lower bound, and page size of a scrollbar control. - * - * RETURNS - * Scrollbar position - * - * NOTE - * For 100 lines of text to be displayed in a window of 25 lines, - * one would for instance use info->nMin=0, info->nMax=75 - * (corresponding to the 76 different positions of the window on - * the text), and info->nPage=25. - */ -INT STDCALL SetScrollInfo( HWND hwnd, INT nBar , -const SCROLLINFO *info , BOOL bRedraw ) -{ - INT action; - INT retVal = SCROLL_SetScrollInfo( hwnd, nBar, info, &action ); - - if( action & SA_SSI_HIDE ) - SCROLL_ShowScrollBar( hwnd, nBar, FALSE, FALSE ); - else - { - if( action & SA_SSI_SHOW ) - if( SCROLL_ShowScrollBar( hwnd, nBar, TRUE, TRUE ) ) - return retVal; /* SetWindowPos() already did the painting */ - - if( bRedraw && (action & SA_SSI_REFRESH)) - SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, TRUE ); - else if( action & SA_SSI_REPAINT_ARROWS ) - SCROLL_RefreshScrollBar( hwnd, nBar, TRUE, FALSE ); - } - return retVal; -} - -INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, - const SCROLLINFO *info, INT *action ) -{ - /* Update the scrollbar state and set action flags according to - * what has to be done graphics wise. */ - - SCROLLBAR_INFO *infoPtr; - UINT new_flags; - -// dbg_decl_str(scroll, 256); - - *action = 0; - - if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0; - if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0; - if ((info->cbSize != sizeof(*info)) && - (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0; - - /* Set the page size */ - - if (info->fMask & SIF_PAGE) - { - // dsprintf(scroll, " page=%d", info->nPage ); - if( infoPtr->Page != info->nPage ) - { - infoPtr->Page = info->nPage; - *action |= SA_SSI_REFRESH; - } - } - - /* Set the scroll pos */ - - if (info->fMask & SIF_POS) - { - // dsprintf(scroll, " pos=%d", info->nPos ); - if( infoPtr->CurVal != info->nPos ) - { - infoPtr->CurVal = info->nPos; - *action |= SA_SSI_REFRESH; - } - } - - /* Set the scroll range */ - - if (info->fMask & SIF_RANGE) - { - // dsprintf(scroll, " min=%d max=%d", info->nMin, info->nMax ); - - /* Invalid range -> range is set to (0,0) */ - if ((info->nMin > info->nMax) || - ((UINT)(info->nMax - info->nMin) >= 0x80000000)) - { - infoPtr->MinVal = 0; - infoPtr->MaxVal = 0; - } - else - { - if( infoPtr->MinVal != info->nMin || - infoPtr->MaxVal != info->nMax ) - { - *action |= SA_SSI_REFRESH; - infoPtr->MinVal = info->nMin; - infoPtr->MaxVal = info->nMax; - } - } - } - - DPRINT( "hwnd=%04x bar=%d %s\n", - hwnd, nBar, dbg_str(scroll)); - - /* Make sure the page size is valid */ - - if (infoPtr->Page < 0) infoPtr->Page = 0; - else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 ) - infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1; - - /* Make sure the pos is inside the range */ - - if (infoPtr->CurVal < infoPtr->MinVal) - infoPtr->CurVal = infoPtr->MinVal; - else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 )) - infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ); - - DPRINT( " new values: page=%d pos=%d min=%d max=%d\n", - infoPtr->Page, infoPtr->CurVal, - infoPtr->MinVal, infoPtr->MaxVal ); - - /* Check if the scrollbar should be hidden or disabled */ - - if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL)) - { - new_flags = infoPtr->flags; - if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 )) - { - /* Hide or disable scroll-bar */ - if (info->fMask & SIF_DISABLENOSCROLL) - { - new_flags = ESB_DISABLE_BOTH; - *action |= SA_SSI_REFRESH; - } - else if (nBar != SB_CTL) - { - *action = SA_SSI_HIDE; - goto done; - } - } - else /* Show and enable scroll-bar */ - { - new_flags = 0; - if (nBar != SB_CTL) - *action |= SA_SSI_SHOW; - } - - if (infoPtr->flags != new_flags) /* check arrow flags */ - { - infoPtr->flags = new_flags; - *action |= SA_SSI_REPAINT_ARROWS; - } - } - -done: - /* Return current position */ - - return infoPtr->CurVal; -} - - - - -/************************************************************************* - * GetScrollInfo (USER.284) - * GetScrollInfo can be used to retrieve the position, upper bound, - * lower bound, and page size of a scrollbar control. - * - * RETURNS STD - */ -BOOL STDCALL GetScrollInfo( HWND hwnd , - INT nBar , LPSCROLLINFO info ) -{ - SCROLLBAR_INFO *infoPtr; - - if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return FALSE; - if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return FALSE; - if ((info->cbSize != sizeof(*info)) && - (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return FALSE; - - if (info->fMask & SIF_PAGE) info->nPage = infoPtr->Page; - if (info->fMask & SIF_POS) info->nPos = infoPtr->CurVal; - if ((info->fMask & SIF_TRACKPOS) && (info->cbSize == sizeof(*info))) - info->nTrackPos = (SCROLL_TrackingWin==hwnd) ? SCROLL_TrackingVal : 0; - if (info->fMask & SIF_RANGE) - { - info->nMin = infoPtr->MinVal; - info->nMax = infoPtr->MaxVal; - } - return (info->fMask & SIF_ALL) != 0; -} - - - - -/************************************************************************* - * SetScrollPos (USER.502) - * - * RETURNS - * Success: Scrollbar position - * Failure: 0 - * - * REMARKS - * Note the ambiguity when 0 is returned. Use GetLastError - * to make sure there was an error (and to know which one). - */ -INT STDCALL SetScrollPos( HWND hwnd , INT nBar , INT nPos ,BOOL bRedraw ) -{ - SCROLLINFO info; - SCROLLBAR_INFO *infoPtr; - INT oldPos; - - if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0; - oldPos = infoPtr->CurVal; - info.cbSize = sizeof(info); - info.nPos = nPos; - info.fMask = SIF_POS; - SetScrollInfo( hwnd, nBar, &info, bRedraw ); - return oldPos; -} - - - - -/************************************************************************* - * GetScrollPos (USER.285) - * - * RETURNS - * Success: Current position - * Failure: 0 - * - * REMARKS - * Note the ambiguity when 0 is returned. Use GetLastError - * to make sure there was an error (and to know which one). - */ -INT STDCALL GetScrollPos( HWND hwnd,INT nBar ) -{ - SCROLLBAR_INFO *infoPtr; - - if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) return 0; - return infoPtr->CurVal; -} - - - - -/************************************************************************* - * SetScrollRange (USER.503) - * - * RETURNS STD - */ -BOOL STDCALL SetScrollRange( HWND hwnd, INT nBar, -INT MinVal, INT MaxVal, BOOL bRedraw ) -{ - SCROLLINFO info; - - info.cbSize = sizeof(info); - info.nMin = MinVal; - info.nMax = MaxVal; - info.fMask = SIF_RANGE; - SetScrollInfo( hwnd, nBar, &info, bRedraw ); - return TRUE; -} - - -/************************************************************************* - * SCROLL_SetNCSbState - * - * Updates both scrollbars at the same time. Used by MDI CalcChildScroll(). - */ -INT SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos, - int hMin, int hMax, int hPos) -{ - INT vA, hA; - SCROLLINFO vInfo, hInfo; - - vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO); - vInfo.nMin = vMin; hInfo.nMin = hMin; - vInfo.nMax = vMax; hInfo.nMax = hMax; - vInfo.nPos = vPos; hInfo.nPos = hPos; - vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS; - - SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_VERT, &vInfo, &vA ); - SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_HORZ, &hInfo, &hA ); - - if( !SCROLL_ShowScrollBar( wndPtr->hwndSelf, SB_BOTH, - (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) ) - { - /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */ - if( vA & SA_SSI_REFRESH ) - SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_VERT, FALSE, TRUE ); - - if( hA & SA_SSI_REFRESH ) - SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_HORZ, FALSE, TRUE ); - } - return 0; -} - - - - -/************************************************************************* - * GetScrollRange (USER.286) - * - * RETURNS STD - */ -BOOL STDCALL GetScrollRange( HWND hwnd, INT nBar, - LPINT lpMin,LPINT lpMax ) -{ - SCROLLBAR_INFO *infoPtr; - - if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ))) - { - if (lpMin) lpMin = 0; - if (lpMax) lpMax = 0; - return FALSE; - } - if (lpMin) *lpMin = infoPtr->MinVal; - if (lpMax) *lpMax = infoPtr->MaxVal; - return TRUE; -} - - -/************************************************************************* - * SCROLL_ShowScrollBar() - * - * Back-end for ShowScrollBar(). Returns FALSE if no action was taken. - * NOTE: fShowV/fShowH must be zero when nBar is SB_HORZ/SB_VERT. - */ -BOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, - BOOL fShowH, BOOL fShowV ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - if (!wndPtr) return FALSE; - DPRINT( "hwnd=%04x bar=%d horz=%d, vert=%d\n", - hwnd, nBar, fShowH, fShowV ); - - switch(nBar) - { - case SB_CTL: - ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE ); - return TRUE; - - case SB_BOTH: - case SB_HORZ: - if (fShowH) - { - fShowH = !(wndPtr->dwStyle & WS_HSCROLL); - wndPtr->dwStyle |= WS_HSCROLL; - } - else /* hide it */ - { - fShowH = (wndPtr->dwStyle & WS_HSCROLL); - wndPtr->dwStyle &= ~WS_HSCROLL; - } - if( nBar == SB_HORZ ) break; - /* fall through */ - - case SB_VERT: - if (fShowV) - { - fShowV = !(wndPtr->dwStyle & WS_VSCROLL); - wndPtr->dwStyle |= WS_VSCROLL; - } - else /* hide it */ - { - fShowV = (wndPtr->dwStyle & WS_VSCROLL); - wndPtr->dwStyle &= ~WS_VSCROLL; - } - break; - - default: - return FALSE; /* Nothing to do! */ - } - - if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */ - { - SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE - | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); - return TRUE; - } - - return FALSE; /* no frame changes */ -} - - - -/************************************************************************* - * SCROLL_FixCaret - */ -WINBOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags) -{ - HWND hCaret = CARET_GetHwnd(); - - if( hCaret ) - { - RECT rc; - CARET_GetRect( &rc ); - if( hCaret == hWnd || - (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) ) - { - POINT pt; - - pt.x = rc.left; pt.y = rc.top; - MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 ); - if( IntersectRect(lprc, lprc, &rc) ) - { - HideCaret(0); - lprc->left = pt.x; lprc->top = pt.y; - return TRUE; - } - } - } - return FALSE; -} - -/************************************************************************* - * ShowScrollBar (USER.5) - * - * RETURNS STD - */ -BOOL STDCALL ShowScrollBar( - HWND hwnd, INT nBar, BOOL fShow ) -{ - SCROLL_ShowScrollBar( hwnd, nBar, (nBar == SB_VERT) ? 0 : fShow, - (nBar == SB_HORZ) ? 0 : fShow ); - return TRUE; -} - - - - -/************************************************************************* - * EnableScrollBar (USER.171) - */ -WINBOOL -STDCALL -EnableScrollBar(HWND hWnd,UINT wSBflags, UINT wArrows) -{ - BOOL bFineWithMe; - SCROLLBAR_INFO *infoPtr; - - DPRINT( "%04x %d %d\n", hwnd, nBar, flags ); - - wArrows &= ESB_DISABLE_BOTH; - - if (wSBflags == SB_BOTH) - { - if (!(infoPtr = SCROLL_GetScrollInfo( hWnd, SB_VERT ))) return FALSE; - if (!(bFineWithMe = (infoPtr->flags == wArrows)) ) - { - infoPtr->flags = wArrows; - SCROLL_RefreshScrollBar( hWnd, SB_VERT, TRUE, TRUE ); - } - wSBflags = SB_HORZ; - } - else - bFineWithMe = TRUE; - - if (!(infoPtr = SCROLL_GetScrollInfo( hWnd, wSBflags ))) return FALSE; - if (bFineWithMe && infoPtr->flags == wArrows) return FALSE; - infoPtr->flags = wArrows; - - SCROLL_RefreshScrollBar( hWnd, wSBflags, TRUE, TRUE ); - return TRUE; -} diff --git a/reactos/lib/user32/controls/static.c b/reactos/lib/user32/controls/static.c deleted file mode 100644 index 779961efd3d..00000000000 --- a/reactos/lib/user32/controls/static.c +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Static control - * - * Copyright David W. Metcalfe, 1993 - * - */ - -#include -#include -#include -#include -#include -#include -#include - - -/* Static Control Styles */ - - - - -//#define SS_ETCHEDHORZ 0x00000010L -//#define SS_ETCHEDVERT 0x00000011L -//#define SS_ETCHEDFRAME 0x00000012L -#define SS_TYPEMASK 0x0000001FL - -//#define SS_NOPREFIX 0x00000080L -//#define SS_NOTIFY 0x00000100L -//#define SS_CENTERIMAGE 0x00000200L -//#define SS_RIGHTJUST 0x00000400L -//#define SS_REALSIZEIMAGE 0x00000800L -//#define SS_SUNKEN 0x00001000L - -/* Static Control Messages */ - -//#define STM_SETICON 0x0170 -//#define STM_GETICON 0x0171 -//#define STM_SETIMAGE 0x0172 -//#define STM_GETIMAGE 0x0173 - -static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc ); -static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc ); -static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc ); -static void STATIC_PaintBitmapfn( WND *wndPtr, HDC hdc ); -static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc ); - -static COLORREF color_windowframe, color_background, color_window; - - -typedef void (*pfPaint)( WND *, HDC ); - -static pfPaint staticPaintFunc[SS_TYPEMASK+1] = -{ - STATIC_PaintTextfn, /* SS_LEFT */ - STATIC_PaintTextfn, /* SS_CENTER */ - STATIC_PaintTextfn, /* SS_RIGHT */ - STATIC_PaintIconfn, /* SS_ICON */ - STATIC_PaintRectfn, /* SS_BLACKRECT */ - STATIC_PaintRectfn, /* SS_GRAYRECT */ - STATIC_PaintRectfn, /* SS_WHITERECT */ - STATIC_PaintRectfn, /* SS_BLACKFRAME */ - STATIC_PaintRectfn, /* SS_GRAYFRAME */ - STATIC_PaintRectfn, /* SS_WHITEFRAME */ - NULL, /* Not defined */ - STATIC_PaintTextfn, /* SS_SIMPLE */ - STATIC_PaintTextfn, /* SS_LEFTNOWORDWRAP */ - NULL, /* SS_OWNERDRAW */ - STATIC_PaintBitmapfn, /* SS_BITMAP */ - NULL, /* SS_ENHMETAFILE */ - STATIC_PaintEtchedfn, /* SS_ETCHEDHORIZ */ - STATIC_PaintEtchedfn, /* SS_ETCHEDVERT */ - STATIC_PaintEtchedfn, /* SS_ETCHEDFRAME */ -}; - -HICON STATIC_LoadIcon(WND *wndPtr,const void *name ) -{ - HICON hIcon; - if ( wndPtr->class->bUnicode ) { - hIcon = LoadIconW(wndPtr->hInstance,(LPCWSTR)name); - } - else - hIcon = LoadIconA(wndPtr->hInstance,(LPCSTR)name); - - return hIcon; -} - -/*********************************************************************** - * STATIC_SetIcon - * - * Set the icon for an SS_ICON control. - */ -HICON STATIC_SetIcon( WND *wndPtr, HICON hicon ) -{ - HICON prevIcon; - STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra; - ICONINFO iconinfo; - BITMAP info; - - if ( !GetIconInfo(hicon, &iconinfo ) ) - return NULL; - - if ( iconinfo.hbmColor ) - GetObject(iconinfo.hbmColor, sizeof(BITMAP),&info); - else - GetObject(iconinfo.hbmMask, sizeof(BITMAP),&info); - - if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_ICON) return 0; - - prevIcon = infoPtr->hIcon; - infoPtr->hIcon = hicon; - if (hicon) - { - SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info.bmWidth, info.bmHeight, - SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); - } - return prevIcon; -} - - -HBITMAP STATIC_LoadBitmap(WND *wndPtr,const void *name ) -{ - HBITMAP hBitmap; - if ( wndPtr->class->bUnicode ) { - hBitmap = LoadBitmapW(wndPtr->hInstance,(LPCWSTR)name); - } - else - hBitmap = LoadBitmapA(wndPtr->hInstance,(LPCSTR)name); - return hBitmap; -} -/*********************************************************************** - * STATIC_SetBitmap - * - * Set the bitmap for an SS_BITMAP control. - */ -HICON STATIC_SetBitmap( WND *wndPtr, HICON hicon ) -{ - - HICON prevIcon; - STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra; - BITMAP info; - - if ( hicon == NULL ) - return NULL; - - GetObject(hicon, sizeof(BITMAP),&info); - - if ((wndPtr->dwStyle & SS_TYPEMASK) != SS_BITMAP) return 0; - - prevIcon = infoPtr->hIcon; - infoPtr->hIcon = hicon; - if (hicon) - { - SetWindowPos( wndPtr->hwndSelf, 0, 0, 0, info.bmWidth, info.bmHeight, - SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); - } - - return prevIcon; - -} - - - - -/*********************************************************************** - * StaticWndProc - */ -LRESULT WINAPI StaticWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, - LPARAM lParam ) -{ - LRESULT lResult = 0; - WND *wndPtr = WIN_FindWndPtr(hWnd); - LONG style = wndPtr->dwStyle & SS_TYPEMASK; - STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra; - - switch (uMsg) - { - case WM_NCCREATE: { - CREATESTRUCT *cs = (CREATESTRUCT *)lParam; - - if ((TWEAK_WineLook > WIN31_LOOK) && (wndPtr->dwStyle & SS_SUNKEN)) - wndPtr->dwExStyle |= WS_EX_STATICEDGE; - - if (style == SS_ICON) - { - if (cs->lpszName) { - STATIC_SetIcon( wndPtr,STATIC_LoadIcon(wndPtr,cs->lpszName)); - } - return 1; - } - if (style == SS_BITMAP) - { - if (cs->lpszName) { - STATIC_SetBitmap( wndPtr,STATIC_LoadBitmap(wndPtr,cs->lpszName)); - } - return 1; - } - - if ( wndPtr->class->bUnicode ) - return DefWindowProcW( hWnd, uMsg, wParam, lParam ); - else - return DefWindowProcA( hWnd, uMsg, wParam, lParam ); - } - case WM_CREATE: - if (style < 0L || style > SS_TYPEMASK) - { - DPRINT( "Unknown style 0x%02lx\n", style ); - lResult = -1L; - break; - } - /* initialise colours */ - color_windowframe = GetSysColor(COLOR_WINDOWFRAME); - color_background = GetSysColor(COLOR_BACKGROUND); - color_window = GetSysColor(COLOR_WINDOW); - break; - - case WM_NCDESTROY: - if (style == SS_ICON) { -/* - * FIXME - * DestroyIcon( STATIC_SetIcon( wndPtr, 0 ) ); - * - * We don't want to do this yet because DestroyIcon is broken. If the icon - * had already been loaded by the application the last thing we want to do is - * GlobalFree the handle. - */ - } else { - if ( wndPtr->class->bUnicode ) - lResult = DefWindowProcW( hWnd, uMsg, wParam, lParam ); - else - lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam ); - - } - break; - - case WM_PAINT: - { - PAINTSTRUCT ps; - BeginPaint( hWnd, &ps ); - if (staticPaintFunc[style]) - (staticPaintFunc[style])( wndPtr, ps.hdc ); - EndPaint( hWnd, &ps ); - } - break; - - case WM_ENABLE: - InvalidateRect( hWnd, NULL, FALSE ); - break; - - case WM_SYSCOLORCHANGE: - color_windowframe = GetSysColor(COLOR_WINDOWFRAME); - color_background = GetSysColor(COLOR_BACKGROUND); - color_window = GetSysColor(COLOR_WINDOW); - InvalidateRect( hWnd, NULL, TRUE ); - break; - - case WM_SETTEXT: - if (style == SS_ICON) - { - if (lParam) { - STATIC_SetIcon( wndPtr,STATIC_LoadIcon(wndPtr,(const void *)lParam)); - } - - } - else if (style == SS_BITMAP) - { - if (lParam) { - STATIC_SetBitmap( wndPtr,STATIC_LoadBitmap(wndPtr,(const void *)lParam)); - } - - } - else { - DEFWND_SetText( wndPtr, (const void *)lParam ); - - } - InvalidateRect( hWnd, NULL, FALSE ); - UpdateWindow( hWnd ); - break; - - case WM_SETFONT: - if (style == SS_ICON) return 0; - if (style == SS_BITMAP) return 0; - infoPtr->hFont = (HFONT)wParam; - if (LOWORD(lParam)) - { - InvalidateRect( hWnd, NULL, FALSE ); - UpdateWindow( hWnd ); - } - break; - - case WM_GETFONT: - return infoPtr->hFont; - - case WM_NCHITTEST: - return HTTRANSPARENT; - - case WM_GETDLGCODE: - return DLGC_STATIC; - - case STM_GETIMAGE: - case STM_GETICON: - return infoPtr->hIcon; - - case STM_SETIMAGE: - /* FIXME: handle wParam */ - lResult = STATIC_SetBitmap( wndPtr, (HBITMAP)lParam ); - InvalidateRect( hWnd, NULL, FALSE ); - UpdateWindow( hWnd ); - break; - - - case STM_SETICON: - lResult = STATIC_SetIcon( wndPtr, (HICON)wParam ); - InvalidateRect( hWnd, NULL, FALSE ); - UpdateWindow( hWnd ); - break; - - default: - if ( wndPtr->class->bUnicode ) - lResult = DefWindowProcW( hWnd, uMsg, wParam, lParam ); - else - lResult = DefWindowProcA( hWnd, uMsg, wParam, lParam ); - break; - } - - return lResult; -} - - -static void STATIC_PaintTextfn( WND *wndPtr, HDC hdc ) -{ - RECT rc; - HBRUSH hBrush; - WORD wFormat; - - LONG style = wndPtr->dwStyle; - STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra; - - GetClientRect( wndPtr->hwndSelf, &rc); - - switch (style & SS_TYPEMASK) - { - case SS_LEFT: - wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP; - break; - - case SS_CENTER: - wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP; - break; - - case SS_RIGHT: - wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK | DT_NOCLIP; - break; - - case SS_SIMPLE: - wFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOCLIP; - break; - - case SS_LEFTNOWORDWRAP: - wFormat = DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS | DT_VCENTER | DT_NOCLIP; - break; - - default: - return; - } - - if (style & SS_NOPREFIX) - wFormat |= DT_NOPREFIX; - - if (infoPtr->hFont) SelectObject( hdc, infoPtr->hFont ); - hBrush = MSG_SendMessage( wndPtr->parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc,(LPARAM) wndPtr->hwndSelf ); - if (!hBrush) hBrush = GetStockObject(WHITE_BRUSH); - FillRect( hdc, &rc, hBrush ); - if (wndPtr->text) { - if ( wndPtr->class->bUnicode ) { - DrawTextW( hdc, wndPtr->text, -1, &rc, wFormat ); - } - else { - DrawTextA( hdc, wndPtr->text, -1, &rc, wFormat ); - } - } - -} - - -static void STATIC_PaintRectfn( WND *wndPtr, HDC hdc ) -{ - RECT rc; - HBRUSH hBrush; - - GetClientRect( wndPtr->hwndSelf, &rc); - - switch (wndPtr->dwStyle & SS_TYPEMASK) - { - case SS_BLACKRECT: - hBrush = CreateSolidBrush(color_windowframe); - FillRect( hdc, &rc, hBrush ); - break; - case SS_GRAYRECT: - hBrush = CreateSolidBrush(color_background); - FillRect( hdc, &rc, hBrush ); - break; - case SS_WHITERECT: - hBrush = CreateSolidBrush(color_window); - FillRect( hdc, &rc, hBrush ); - break; - case SS_BLACKFRAME: - hBrush = CreateSolidBrush(color_windowframe); - FrameRect( hdc, &rc, hBrush ); - break; - case SS_GRAYFRAME: - hBrush = CreateSolidBrush(color_background); - FrameRect( hdc, &rc, hBrush ); - break; - case SS_WHITEFRAME: - hBrush = CreateSolidBrush(color_window); - FrameRect( hdc, &rc, hBrush ); - break; - default: - return; - } - DeleteObject( hBrush ); -} - - -static void STATIC_PaintIconfn( WND *wndPtr, HDC hdc ) -{ - RECT rc; - HBRUSH hbrush; - STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra; - - GetClientRect( wndPtr->hwndSelf, &rc ); - hbrush = MSG_SendMessage( wndPtr->parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc, (LPARAM)wndPtr->hwndSelf ); - FillRect( hdc, &rc, hbrush ); - if (infoPtr->hIcon) DrawIcon( hdc, rc.left, rc.top, infoPtr->hIcon ); -} - -static void STATIC_PaintBitmapfn(WND *wndPtr, HDC hdc ) -{ - RECT rc; - HBRUSH hbrush; - STATICINFO *infoPtr = (STATICINFO *)wndPtr->wExtra; - HDC hMemDC; - HBITMAP oldbitmap; - - GetClientRect( wndPtr->hwndSelf, &rc ); - hbrush = MSG_SendMessage( wndPtr->parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc,(LPARAM) wndPtr->hwndSelf ); - FillRect( hdc, &rc, hbrush ); - if (infoPtr->hIcon) { - BITMAP bmp; - GetObject( infoPtr->hIcon, sizeof(BITMAP),&bmp); - - if (!(hMemDC = CreateCompatibleDC( hdc ))) return; - - oldbitmap = SelectObject(hMemDC,infoPtr->hIcon); - BitBlt(hdc,bmp.bmWidth,bmp.bmHeight,bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY); -// BitBlt(hdc,bmp.size.cx,bmp.size.cy,bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY); - DeleteDC(hMemDC); - - } -} - - -static void STATIC_PaintEtchedfn( WND *wndPtr, HDC hdc ) -{ - RECT rc; - HBRUSH hbrush; - HPEN hpen; - - if (TWEAK_WineLook == WIN31_LOOK) - return; - - GetClientRect( wndPtr->hwndSelf, &rc ); - hbrush = MSG_SendMessage( wndPtr->parent, WM_CTLCOLORSTATIC, - (WPARAM)hdc, (LPARAM)wndPtr->hwndSelf ); - FillRect( hdc, &rc, hbrush ); - - switch (wndPtr->dwStyle & SS_TYPEMASK) - { - case SS_ETCHEDHORZ: - hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW)); - MoveToEx (hdc, rc.left, rc.bottom / 2 - 1, NULL); - LineTo (hdc, rc.right - 1, rc.bottom / 2 - 1); - SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT)); - MoveToEx (hdc, rc.left, rc.bottom / 2, NULL); - LineTo (hdc, rc.right, rc.bottom / 2); - LineTo (hdc, rc.right, rc.bottom / 2 - 1); - SelectObject (hdc, hpen); - break; - - case SS_ETCHEDVERT: - hpen = SelectObject (hdc, GetSysColorPen (COLOR_3DSHADOW)); - MoveToEx (hdc, rc.right / 2 - 1, rc.top, NULL); - LineTo (hdc, rc.right / 2 - 1, rc.bottom - 1); - SelectObject (hdc, GetSysColorPen (COLOR_3DHIGHLIGHT)); - MoveToEx (hdc, rc.right / 2, rc.top, NULL); - LineTo (hdc, rc.right / 2, rc.bottom); - LineTo (hdc, rc.right / 2 -1 , rc.bottom); - SelectObject (hdc, hpen); - break; - - case SS_ETCHEDFRAME: - DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT); - break; - } -} - diff --git a/reactos/lib/user32/controls/widgets.c b/reactos/lib/user32/controls/widgets.c deleted file mode 100644 index 5ecff11072c..00000000000 --- a/reactos/lib/user32/controls/widgets.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Windows widgets (built-in window classes) - * - * Copyright 1993 Alexandre Julliard - */ - -#define UNICODE -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/* Built-in classes */ -#ifndef DLGWINDOWEXTRA -#define DLGWINDOWEXTRA sizeof(DIALOGINFO) -#endif - -static WNDCLASS WIDGETS_BuiltinClasses[BIC_NB_CLASSES+1] = -{ - /* BIC_BUTTON */ - { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, - ButtonWndProc, 0, sizeof(BUTTONINFO), 0, 0, - (HCURSOR)IDC_ARROW, 0, 0, BUTTON_CLASS_NAME }, - /* BIC_EDIT */ - { CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/, - EditWndProc, 0, sizeof(void *), 0, 0, - (HCURSOR)IDC_IBEAM, 0, 0, EDIT_CLASS_NAME }, - /* BIC_LISTBOX */ - { CS_GLOBALCLASS | CS_DBLCLKS /*| CS_PARENTDC*/, - ListBoxWndProc, 0, sizeof(void *), 0, 0, - (HCURSOR)IDC_ARROW, 0, 0, LISTBOX_CLASS_NAME }, - /* BIC_COMBO */ - { CS_GLOBALCLASS | CS_PARENTDC | CS_DBLCLKS, - ComboWndProc, 0, sizeof(void *), 0, 0, - (HCURSOR)IDC_ARROW, 0, 0, COMBOBOX_CLASS_NAME }, - /* BIC_COMBOLB */ - { CS_GLOBALCLASS | CS_DBLCLKS | CS_SAVEBITS, ComboLBWndProc, - 0, sizeof(void *), 0, 0, (HCURSOR)IDC_ARROW, 0, 0,COMBOLBOX_CLASS_NAME}, - /* BIC_POPUPMENU */ -// { CS_GLOBALCLASS | CS_SAVEBITS, PopupMenuWndProc, 0, sizeof(HMENU), -// 0, 0, (HCURSOR)IDC_ARROW, NULL_BRUSH, 0, POPUPMENU_CLASS_NAME }, - /* BIC_STATIC */ - { CS_GLOBALCLASS | CS_PARENTDC, StaticWndProc, - 0, sizeof(STATICINFO), 0, 0, (HCURSOR)IDC_ARROW, 0, 0, STATIC_CLASS_NAME }, - /* BIC_SCROLL */ - { CS_GLOBALCLASS | CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_PARENTDC, - ScrollBarWndProc, 0, sizeof(SCROLLBAR_INFO), 0, 0, - (HCURSOR)IDC_ARROW, 0, 0, SCROLLBAR_CLASS_NAME}, - /* BIC_MDICLIENT */ -// { CS_GLOBALCLASS, MDIClientWndProc, -// 0, sizeof(MDICLIENTINFO), 0, 0, 0, LTGRAY_BRUSH, 0, "MDIClient" }, - /* BIC_DESKTOP */ -//sizeof(DESKTOPINFO) - { CS_GLOBALCLASS, DesktopWndProc, 0, 1024, - 0, 0, (HCURSOR)IDC_ARROW, 0, 0, DESKTOP_CLASS_NAME }, - /* BIC_DIALOG */ - { CS_GLOBALCLASS | CS_SAVEBITS, DefDlgProc, 100, 100, - 0, 0, (HCURSOR)IDC_ARROW, 0, 0, DIALOG_CLASS_NAMEW }, - /* BIC_ICONTITLE */ - { CS_GLOBALCLASS, IconTitleWndProc, 0, 0, - 0, 0, (HCURSOR)IDC_ARROW, 0, 0, ICONTITLE_CLASS_NAME }, - /* BIC_DIALOG Ascii */ - { CS_GLOBALCLASS, DefDlgProcA, 100, 100, - 0, 0, (HCURSOR)IDC_ARROW, 0, 0, (LPWSTR)DIALOG_CLASS_NAME_A } -}; - - -static ATOM bicAtomTable[BIC_NB_CLASSES+1]; - -/*********************************************************************** - * WIDGETS_Init - * - * Initialize the built-in window classes. - */ -WINBOOL WIDGETS_Init(void) -{ - int i; - WNDCLASS *cls = WIDGETS_BuiltinClasses; - - /* Create builtin classes */ - - for (i = 0; i < BIC_NB_CLASSES; i++) - { - - cls[i].hCursor = LoadCursorW( 0, (LPCWSTR)cls[i].hCursor ); - if (!(bicAtomTable[i] = RegisterClassW( &cls[i] ))) return FALSE; - } - - cls[i].hCursor = LoadCursorW( 0, (LPCWSTR)cls[i].hCursor ); - if (!(bicAtomTable[i] = RegisterClassA( &cls[i] ))) return FALSE; - - - return TRUE; -} - -LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam ) -{ - return 0; -} - -/*********************************************************************** - * WIDGETS_IsControl - * - * Check whether pWnd is a built-in control or not. - */ -WINBOOL WIDGETS_IsControl( WND* pWnd, BUILTIN_CLASS cls ) -{ - if( cls >= BIC_NB_CLASSES ) - return FALSE; - return (pWnd->class->atomName == bicAtomTable[cls]); -} diff --git a/reactos/lib/user32/graphics/caret.c b/reactos/lib/user32/graphics/caret.c deleted file mode 100644 index bf818360dad..00000000000 --- a/reactos/lib/user32/graphics/caret.c +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Caret functions - * - * Copyright 1993 David Metcalfe - * Copyright 1996 Frans van Dorsselaer - */ - -#include -#include -#include - -static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 }; - - -WINBOOL STDCALL CreateCaret( HWND hwnd, HBITMAP bitmap, - INT width, INT height ) -{ - DPRINT("hwnd=%04x\n",(UINT) hwnd); - - if (!hwnd) return FALSE; - - /* if cursor already exists, destroy it */ - if (Caret.hwnd) DestroyCaret(); - - if (bitmap && ((UINT)bitmap != 1)) - { - BITMAP bmp; - if (!GetObject( bitmap, sizeof(bmp), &bmp )) return FALSE; - Caret.width = bmp.bmWidth; - Caret.height = bmp.bmHeight; - /* FIXME: we should make a copy of the bitmap instead of a brush */ - Caret.hBrush = CreatePatternBrush( bitmap ); - } - else - { - Caret.width = width ? width : GetSystemMetrics(SM_CXBORDER); - Caret.height = height ? height : GetSystemMetrics(SM_CYBORDER); - Caret.hBrush = CreateSolidBrush(bitmap ? - GetSysColor(COLOR_GRAYTEXT) : - GetSysColor(COLOR_WINDOW) ); - } - - Caret.hwnd = hwnd; - Caret.hidden = 1; - Caret.on = FALSE; - Caret.x = 0; - Caret.y = 0; - - Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 ); - return TRUE; -} - - - -WINBOOL STDCALL DestroyCaret(void) -{ - if (!Caret.hwnd) return FALSE; - - DPRINT("hwnd=%04x, timerid=%d\n", (UINT)Caret.hwnd,(UINT) Caret.timerid); - - CARET_KillTimer(); - CARET_DisplayCaret(CARET_OFF); - DeleteObject( Caret.hBrush ); - Caret.hwnd = 0; - return TRUE; -} - - - -WINBOOL STDCALL SetCaretPos( INT x, INT y) -{ - if (!Caret.hwnd) return FALSE; - if ((x == Caret.x) && (y == Caret.y)) return TRUE; - - DPRINT("x=%d, y=%d\n", x, y); - - CARET_KillTimer(); - CARET_DisplayCaret(CARET_OFF); - Caret.x = x; - Caret.y = y; - if (!Caret.hidden) - { - CARET_DisplayCaret(CARET_ON); - CARET_SetTimer(); - } - return TRUE; -} - - - - - -/***************************************************************** - * HideCaret (USER.317) - */ -WINBOOL STDCALL HideCaret( HWND hwnd ) -{ - if (!Caret.hwnd) return FALSE; - if (hwnd && (Caret.hwnd != hwnd)) return FALSE; - - DPRINT("hwnd=%04x, hidden=%d\n", - hwnd, Caret.hidden); - - CARET_KillTimer(); - CARET_DisplayCaret(CARET_OFF); - Caret.hidden++; - return TRUE; -} - - - - -/***************************************************************** - * ShowCaret (USER.529) - */ -WINBOOL STDCALL ShowCaret( HWND hwnd ) -{ - if (!Caret.hwnd) return FALSE; - if (hwnd && (Caret.hwnd != hwnd)) return FALSE; - - DPRINT("hwnd=%04x, hidden=%d\n", - hwnd, Caret.hidden); - - if (Caret.hidden) - { - Caret.hidden--; - if (!Caret.hidden) - { - CARET_DisplayCaret(CARET_ON); - CARET_SetTimer(); - } - } - return TRUE; -} - - - -/***************************************************************** - * SetCaretBlinkTime (USER.465) - */ -WINBOOL STDCALL SetCaretBlinkTime( UINT msecs ) -{ - if (!Caret.hwnd) return FALSE; - - DPRINT("hwnd=%04x, msecs=%d\n", - Caret.hwnd, msecs); - - Caret.timeout = msecs; - CARET_ResetTimer(); - return TRUE; -} - - - - -/***************************************************************** - * GetCaretBlinkTime (USER.209) - */ -UINT STDCALL GetCaretBlinkTime(void) -{ - return Caret.timeout; -} - - - - - -/***************************************************************** - * GetCaretPos (USER.210) - */ -WINBOOL STDCALL GetCaretPos( LPPOINT pt ) -{ - if (!Caret.hwnd || !pt) return FALSE; - pt->x = Caret.x; - pt->y = Caret.y; - return TRUE; -} - - -/***************************************************************** - * CARET_GetHwnd - */ -HWND CARET_GetHwnd(void) -{ - return Caret.hwnd; -} - -/***************************************************************** - * CARET_GetRect - */ -void CARET_GetRect(LPRECT lprc) -{ - lprc->right = (lprc->left = Caret.x) + Caret.width - 1; - lprc->bottom = (lprc->top = Caret.y) + Caret.height - 1; -} - -/***************************************************************** - * CARET_DisplayCaret - */ -void CARET_DisplayCaret( DISPLAY_CARET status ) -{ - HDC hdc; - HBRUSH hPrevBrush; - - if (Caret.on && (status == CARET_ON)) return; - if (!Caret.on && (status == CARET_OFF)) return; - - /* So now it's always a toggle */ - - Caret.on = !Caret.on; - /* do not use DCX_CACHE here, for x,y,width,height are in logical units */ - if (!(hdc = GetDCEx( Caret.hwnd, 0, DCX_USESTYLE /*| DCX_CACHE*/ ))) return; - hPrevBrush = SelectObject( hdc, Caret.hBrush ); - PatBlt( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT ); - SelectObject( hdc, hPrevBrush ); - ReleaseDC( Caret.hwnd, hdc ); -} - - -/***************************************************************** - * CARET_Callback - */ -VOID CALLBACK CARET_Callback( HWND hwnd, UINT msg, UINT id, DWORD ctime) -{ - DPRINT("hwnd=%04x, timerid=%d, caret=%d\n", hwnd, id, Caret.on); - CARET_DisplayCaret(CARET_TOGGLE); -} - - -/***************************************************************** - * CARET_SetTimer - */ -void CARET_SetTimer(void) -{ - if (Caret.timerid) - KillTimer( (HWND)0, Caret.timerid ); - Caret.timerid = SetTimer( (HWND)0, 0, Caret.timeout,CARET_Callback ); -} - - -/***************************************************************** - * CARET_ResetTimer - */ -void CARET_ResetTimer(void) -{ - if (Caret.timerid) - { - KillTimer( (HWND)0, Caret.timerid ); - Caret.timerid = SetTimer( (HWND)0, 0, Caret.timeout, - CARET_Callback ); - } -} - - -/***************************************************************** - * CARET_KillTimer - */ -void CARET_KillTimer(void) -{ - if (Caret.timerid) - { - KillTimer( (HWND)0, Caret.timerid ); - Caret.timerid = 0; - } -} - - - -/********************************************************************** - * CreateIconFromResource (USER32.76) - */ -HICON STDCALL CreateIconFromResource( LPBYTE bits, UINT cbSize, - WINBOOL bIcon, DWORD dwVersion) -{ - return CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, 0,0,0); -} - - -/********************************************************************** - * CreateIconFromResourceEx (USER32.77) - */ -HICON STDCALL CreateIconFromResourceEx( LPBYTE bits, UINT cbSize, - WINBOOL bIcon, DWORD dwVersion, - INT width, INT height, - UINT cFlag ) -{ -/* - TDB* pTask = (TDB*)GlobalLock( GetCurrentTask() ); - if( pTask ) - return CURSORICON_CreateFromResource( pTask->hInstance, 0, bits, cbSize, bIcon, dwVersion, - width, height, cFlag ); -*/ - return 0; -} - - - diff --git a/reactos/lib/user32/graphics/draw.c b/reactos/lib/user32/graphics/draw.c deleted file mode 100644 index acb1182d8ec..00000000000 --- a/reactos/lib/user32/graphics/draw.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -//#include -#include - -WINBOOL STDCALL DrawEdge( HDC hdc, LPRECT rc, UINT edge, UINT flags ) -{ - DPRINT("graphics %04x %d,%d-%d,%d %04x %04x\n", - hdc, rc->left, rc->top, rc->right, rc->bottom, edge, flags ); - - if(flags & BF_DIAGONAL) - return UITOOLS95_DrawDiagEdge(hdc, rc, edge, flags); - else - return UITOOLS95_DrawRectEdge(hdc, rc, edge, flags); -} diff --git a/reactos/lib/user32/graphics/fill.c b/reactos/lib/user32/graphics/fill.c deleted file mode 100644 index 140f5e16df4..00000000000 --- a/reactos/lib/user32/graphics/fill.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include - - -void FillWindow( HWND hwndParent, HWND hwnd, HDC hdc, HBRUSH hbrush ) -{ - RECT rect; - GetClientRect( hwnd, &rect ); - PaintRect( hwndParent, hwnd, hdc, hbrush, &rect ); -} - - - - - -/*********************************************************************** - * PaintRect (USER.325) - */ -void PaintRect( HWND hwndParent, HWND hwnd, HDC hdc, - HBRUSH hbrush, const RECT *rect) -{ - if( hbrush <= CTLCOLOR_MAX ) - { - if( hwndParent ) - hbrush = PAINT_GetControlBrush( hwndParent, hwnd, hdc, (UINT)hbrush ); - else - return; - } - if( hbrush ) - FillRect( hdc, rect, hbrush ); -} - - - - - -INT STDCALL FrameRect( HDC hdc, const RECT *rect, HBRUSH hbrush ) -{ - HBRUSH prevBrush; - //int left, top, right, bottom; - - if ( hdc == NULL ) - return 0; - - //left = XLPTODP( dc, rect->left ); - //top = YLPTODP( dc, rect->top ); - //right = XLPTODP( dc, rect->right ); - //bottom = YLPTODP( dc, rect->bottom ); - - //if ( (right <= left) || (bottom <= top) ) return 0; - if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0; - - PatBlt( hdc, rect->left, rect->top, 1, - rect->bottom - rect->top, PATCOPY ); - PatBlt( hdc, rect->right - 1, rect->top, 1, - rect->bottom - rect->top, PATCOPY ); - PatBlt( hdc, rect->left, rect->top, - rect->right - rect->left, 1, PATCOPY ); - PatBlt( hdc, rect->left, rect->bottom - 1, - rect->right - rect->left, 1, PATCOPY ); - - SelectObject( hdc, prevBrush ); - return 1; -} - - -INT STDCALL FillRect( HDC hdc, const RECT *rect, HBRUSH hbrush ) -{ - HBRUSH prevBrush; - - if (!(prevBrush = SelectObject( hdc, hbrush ))) return 0; - PatBlt( hdc, rect->left, rect->top, - rect->right - rect->left, rect->bottom - rect->top, PATCOPY ); - SelectObject( hdc, prevBrush ); - return 1; -} - - -WINBOOL STDCALL InvertRect( HDC hDC, CONST RECT *lprc) -{ - return PatBlt( hDC, lprc->left, lprc->top, - lprc->right - lprc->left, lprc->bottom - lprc->top, DSTINVERT ); -} diff --git a/reactos/lib/user32/graphics/icon.c b/reactos/lib/user32/graphics/icon.c deleted file mode 100644 index 9f2cda55bea..00000000000 --- a/reactos/lib/user32/graphics/icon.c +++ /dev/null @@ -1,208 +0,0 @@ - -#include - -//#include - -HICON LoadStandardIcon(UINT IconId); - -HICON -STDCALL -CreateIcon( - HINSTANCE hInstance, - int nWidth, - int nHeight, - BYTE cPlanes, - BYTE cBitsPixel, - CONST BYTE *lpbANDbits, - CONST BYTE *lpbXORbits) -{ -#if 0 - - ICONINFO IconInfo; - IconInfo.fIcon = TRUE; - IconInfo.hbmMask = NULL; - IconInfo.hbmColor = NULL; - return CreateIconIndirect( &IconInfo ); -#endif -} - -HICON -STDCALL -CreateIconIndirect( - PICONINFO lpIconInfo) -{ - BITMAP bmpXor,bmpAnd; - HICON hObj; - int sizeXor,sizeAnd; - - GetObject(lpIconInfo->hbmColor,sizeof(BITMAP),&bmpXor); - GetObject(lpIconInfo->hbmMask,sizeof(BITMAP),&bmpAnd); - - - - sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes; - sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes; - - hObj = GlobalAlloc( GMEM_MOVEABLE, - sizeof(ICONINFO) + sizeXor + sizeAnd ); - if (hObj) - { - ICONINFO *info; - - info = (ICONINFO *)( hObj ); - info->xHotspot = lpIconInfo->xHotspot; - info->yHotspot = lpIconInfo->yHotspot; - //info->nWidth = bmpXor.bmWidth; - //info->nHeight = bmpXor.bmHeight; - //info->nWidthBytes = bmpXor.bmWidthBytes; - //info->bPlanes = bmpXor.bmPlanes; - //info->bBitsPerPixel = bmpXor.bmBitsPixel; - - /* Transfer the bitmap bits to the CURSORICONINFO structure */ - - GetBitmapBits( lpIconInfo->hbmMask ,sizeAnd,(char*)(info + 1) ); - GetBitmapBits( lpIconInfo->hbmColor,sizeXor,(char*)(info + 1) +sizeAnd); - - } - return hObj; -} - -WINBOOL -STDCALL -DestroyIcon( - HICON hIcon) -{ - return FALSE; -} - -HICON -STDCALL -CopyIcon( - HICON hIcon) -{ -} - - -WINBOOL -STDCALL -GetIconInfo( - HICON hIcon, - PICONINFO piconinfo) -{ - - return TRUE; -} - - - - -HICON -STDCALL -LoadIconA(HINSTANCE hInstance,LPCSTR lpIconName ) -{ - HRSRC hrsrc; - ICONINFO *IconInfo; - - if ( hInstance == NULL ) { - return LoadStandardIcon((UINT)lpIconName); - } -//RT_GROUP_ICON - hrsrc = FindResourceExA(hInstance,RT_GROUP_ICON, lpIconName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)); - - if ( hrsrc == NULL ) - return NULL; - - IconInfo = (ICONINFO *)LoadResource(hInstance, hrsrc); - if ( IconInfo != NULL || IconInfo->fIcon == FALSE ) - return NULL; - - return CreateIconIndirect(IconInfo); -} - -HICON -STDCALL -LoadIconW(HINSTANCE hInstance,LPCWSTR lpIconName ) -{ - HRSRC hrsrc; - ICONINFO *IconInfo; - - if ( hInstance == NULL ) { - return LoadStandardIcon((UINT)lpIconName); - } - - hrsrc = FindResourceW(hInstance,lpIconName,RT_GROUP_ICON); - if ( hrsrc == NULL ) - return NULL; - - IconInfo = (ICONINFO *)LoadResource(hInstance, hrsrc); - if ( IconInfo != NULL || IconInfo->fIcon == FALSE ) - return NULL; - - return CreateIconIndirect(IconInfo); -} - -HICON LoadStandardIcon(UINT IconId) -{ - HMODULE hModule = LoadLibraryA("user32.dll"); - switch (IconId ) - { - case (UINT)IDI_APPLICATION: - IconId = 100; - return LoadIconW(hModule,(LPWSTR)IconId); - break; - case (UINT)IDI_ASTERISK: - // - IconId = 103; - return LoadIconW(hModule,(LPWSTR)IconId); - break; - case (UINT)IDI_EXCLAMATION: - IconId = 101; - return LoadIconW(hModule,(LPWSTR)IconId); - break; - case (UINT)IDI_HAND: - // - return LoadIconW(hModule,(LPWSTR)MAKEINTRESOURCE(104)); - break; - case (UINT)IDI_QUESTION: - IconId = 102; - return LoadIconW(hModule,(LPWSTR)IconId); - break; - case (UINT)IDI_WINLOGO: - IconId = 105; - return LoadIconW(hModule,(LPWSTR)IconId); - break; - default: - return NULL; - break; - - } - return NULL; -} - -WINBOOL STDCALL DrawIcon(HDC hDC, int xLeft, int yTop, HICON hIcon ) -{ - - return DrawIconEx( hDC, xLeft, yTop,hIcon, -1, -1,0,NULL, DI_DEFAULTSIZE); -} - -WINBOOL -STDCALL -DrawIconEx(HDC hdc, int xLeft, int yTop, - HICON hIcon, int cxWidth, int cyWidth, - UINT istepIfAniCur, HBRUSH hbrFlickerFreeDraw, UINT diFlags) -{ - //ICONINFO IconInfo; - //SIZE Size;; - //GetIconInfo(hIcon,&IconInfo); - //GetBitmapDimensionEx(IconInfo.hbmMask,&Size); - return FALSE; -} - -WINBOOL -STDCALL -DrawFocusRect( - HDC hDC, - CONST RECT * lprc) -{ - return FALSE; -} diff --git a/reactos/lib/user32/graphics/rect.c b/reactos/lib/user32/graphics/rect.c deleted file mode 100644 index 88409dca2a4..00000000000 --- a/reactos/lib/user32/graphics/rect.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Rectangle-related functions - * - * CopyxRight 1993, 1996 Alexandre Julliard - * - */ - -#include -#define MIN min -#define MAX max - -#include -#include - -WINBOOL -STDCALL -SetRect( - LPRECT lprc, - int xLeft, - int yTop, - int xRight, - int yBottom) -{ - if ( lprc == NULL ) - return FALSE; - lprc->left = xLeft; - lprc->right = xRight; - lprc->top = yTop; - lprc->bottom = yBottom; - return TRUE; -} - - - - -/*********************************************************************** - * SetRectEmpty32 (USER32.500) - */ -WINBOOL STDCALL SetRectEmpty( LPRECT lprc ) -{ - if ( lprc == NULL ) - return FALSE; - lprc->left = lprc->right = lprc->top = lprc->bottom = 0; - return TRUE; -} - - - -//added memcpy and check BD - -/*********************************************************************** - * CopyRect32 (USER32.62) - */ -WINBOOL -STDCALL -CopyRect( - LPRECT lprcDst, - CONST RECT *lprcSrc) -{ - if ( lprcDst == NULL || lprcSrc == NULL ) - return FALSE; - *lprcDst = *lprcSrc; - return TRUE; -} - - - - - -/*********************************************************************** - * IsRectEmpty32 (USER32.347) - */ -WINBOOL STDCALL IsRectEmpty( const RECT *lprc ) -{ - if ( lprc == NULL ) - return TRUE; - return ((lprc->left == lprc->right) || (lprc->top == lprc->bottom)); -} - - - - - - -/*********************************************************************** - * PtInRect32 (USER32.424) - */ -WINBOOL -STDCALL -PtInRect( - CONST RECT *lprc, - POINT pt) -{ - return ((pt.x >= lprc->left) && (pt.x < lprc->right) && - (pt.y >= lprc->top) && (pt.y < lprc->bottom)); -} - - - - -/*********************************************************************** - * OffsetRect32 (USER32.406) - */ -WINBOOL -STDCALL -OffsetRect( - LPRECT lprc, - int dx, - int dy) -{ - if ( lprc == NULL ) - return FALSE; - lprc->left += dx; - lprc->right += dx; - lprc->top += dy; - lprc->bottom += dy; - return TRUE; -} - - - - - -/*********************************************************************** - * InflateRect32 (USER32.321) - */ -WINBOOL STDCALL InflateRect( LPRECT lprc, INT dx, INT dy ) -{ - lprc->left -= dx; - lprc->top -= dy; - lprc->right += dx; - lprc->bottom += dy; - return TRUE; -} - - - - - -/*********************************************************************** - * IntersectRect32 (USER32.327) - */ -WINBOOL -STDCALL -IntersectRect( - LPRECT lprcDst, - CONST RECT *lprcSrc1, - CONST RECT *lprcSrc2) -{ - if (IsRectEmpty(lprcSrc1) || IsRectEmpty(lprcSrc2) || - (lprcSrc1->left >= lprcSrc2->right) || (lprcSrc2->left >= lprcSrc1->right) || - (lprcSrc1->top >= lprcSrc2->bottom) || (lprcSrc2->top >= lprcSrc1->bottom)) - { - SetRectEmpty( lprcDst ); - return FALSE; - } - lprcDst->left = MAX( lprcSrc1->left, lprcSrc2->left ); - lprcDst->right = MIN( lprcSrc1->right, lprcSrc2->right ); - lprcDst->top = MAX( lprcSrc1->top, lprcSrc2->top ); - lprcDst->bottom = MIN( lprcSrc1->bottom, lprcSrc2->bottom ); - return TRUE; -} - - - - -/*********************************************************************** - * UnionRect32 (USER32.559) - */ -WINBOOL STDCALL UnionRect( LPRECT lprcDst, const RECT *lprcSrc1, - const RECT *lprcSrc2 ) -{ - if (IsRectEmpty(lprcSrc1)) - { - if (IsRectEmpty(lprcSrc2)) - { - SetRectEmpty( lprcDst ); - return FALSE; - } - else *lprcDst = *lprcSrc2; - } - else - { - if (IsRectEmpty(lprcSrc2)) - *lprcDst = *lprcSrc1; - else - { - lprcDst->left = MIN( lprcSrc1->left, lprcSrc2->left ); - lprcDst->right = MAX( lprcSrc1->right, lprcSrc2->right ); - lprcDst->top = MIN( lprcSrc1->top, lprcSrc2->top ); - lprcDst->bottom = MAX( lprcSrc1->bottom, lprcSrc2->bottom ); - } - } - return TRUE; -} - - - - -/*********************************************************************** - * EqualRect32 (USER32.194) - */ -WINBOOL -STDCALL -EqualRect( - CONST RECT *lprc1, - CONST RECT *lprc2) -{ - return ((lprc1->left == lprc2->left) && (lprc1->right == lprc2->right) && - (lprc1->top == lprc2->top) && (lprc1->bottom == lprc2->bottom)); -} - - - - - -/*********************************************************************** - * SubtractRect32 (USER32.536) - */ -WINBOOL -STDCALL -SubtractRect( - LPRECT lprcDst, - CONST RECT *lprcSrc1, - CONST RECT *lprcSrc2) -{ - RECT tmp; - - if (IsRectEmpty( lprcSrc1 )) - { - SetRectEmpty( lprcDst ); - return FALSE; - } -// changed BD - CopyRect(lprcDst,lprcSrc1); - - if (IntersectRect( &tmp, lprcSrc1, lprcSrc2 )) - { - if (EqualRect( &tmp, lprcDst )) - { - SetRectEmpty( lprcDst ); - return FALSE; - } - if ((tmp.top == lprcDst->top) && (tmp.bottom == lprcDst->bottom)) - { - if (tmp.left == lprcDst->left) lprcDst->left = tmp.right; - else if (tmp.right == lprcDst->right) lprcDst->right = tmp.left; - } - else if ((tmp.left == lprcDst->left) && (tmp.right == lprcDst->right)) - { - if (tmp.top == lprcDst->top) lprcDst->top = tmp.bottom; - else if (tmp.bottom == lprcDst->bottom) lprcDst->bottom = tmp.top; - } - } - return TRUE; -} diff --git a/reactos/lib/user32/graphics/syscol.c b/reactos/lib/user32/graphics/syscol.c deleted file mode 100644 index 6374eea5f97..00000000000 --- a/reactos/lib/user32/graphics/syscol.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Support for system colors - * - * Copyright David W. Metcalfe, 1993 - * Copyright Alexandre Julliard, 1994 - * - */ - - -#include -#include - -typedef struct _sysco -{ - const char *name; - const char *value; -} syscol; - -static int DefSysColors[] = -{ - 223,223,223, /* COLOR_SCROLLBAR */ - 192,192,192, /* COLOR_BACKGROUND */ - 0,0,128, /* COLOR_ACTIVECAPTION */ - 128,128,128, /* COLOR_INACTIVECAPTION */ - 192,192,192, /* COLOR_MENU */ - 255,255,255, /* COLOR_WINDOW */ - 0,0,0, /* COLOR_WINDOWFRAME */ - 0,0,0, /* COLOR_MENUTEXT */ - 0,0,0, /* COLOR_WINDOWTEXT */ - 255,255,255, /* COLOR_CAPTIONTEXT */ - 192,192,192, /* COLOR_ACTIVEBORDER */ - 192,192,192, /* COLOR_INACTIVEBORDER */ - 128,128,128, /* COLOR_APPWORKSPACE */ - 0,0,128, /* COLOR_HIGHLIGHT */ - 255,255,255, /* COLOR_HIGHLIGHTTEXT */ - 192,192,192, /* COLOR_BTNFACE */ - 128,128,128, /* COLOR_BTNSHADOW */ - 192,192,192, /* COLOR_GRAYTEXT */ - 0,0,0, /* COLOR_BTNTEXT */ - 0,0,0,/* COLOR_INACTIVECAPTIONTEXT */ - 255,255,255, /* COLOR_BTNHIGHLIGHT */ - 0,0,0, /* COLOR_3DDKSHADOW */ - 223,223,223, /* COLOR_3DLIGHT */ - 0,0,0, /* COLOR_INFOTEXT */ - 255,255,192, /* COLOR_INFOBK */ - 184,180,184, /* COLOR_ALTERNATEBTNFACE */ - 0,0,255, /* COLOR_HOTLIGHT */ - 16,132,208, /* COLOR_GRADIENTACTIVECAPTION */ - 184,180,184 /* COLOR_GRADIENTINACTIVECAPTION */ -}; - -//#define NUM_SYS_COLORS (COLOR_GRADIENTINACTIVECAPTION+1) -#define NUM_SYS_COLORS 29 - -static COLORREF SysColors[NUM_SYS_COLORS]; -static HBRUSH SysColorBrushes[NUM_SYS_COLORS]; -static HPEN SysColorPens[NUM_SYS_COLORS]; - -static char bSysColorInit = FALSE; - -DWORD STDCALL GetSysColor( INT nIndex ) -{ - if ( bSysColorInit == FALSE ) - SYSCOLOR_Init(); - if (nIndex >= 0 && nIndex < NUM_SYS_COLORS) - return SysColors[nIndex]; - else - return 0; -} - - - -/************************************************************************* - * SetSysColors (USER.505) - */ -WINBOOL STDCALL SetSysColors( INT nChanges, const INT *lpSysColor, - const COLORREF *lpColorValues ) -{ - int i; - - if ( bSysColorInit == FALSE ) - SYSCOLOR_Init(); - for (i = 0; i < nChanges; i++) - { - SYSCOLOR_SetColor( lpSysColor[i], lpColorValues[i] ); - } - - /* Send WM_SYSCOLORCHANGE message to all windows */ - - SendMessageA( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0 ); - - /* Repaint affected portions of all visible windows */ - - RedrawWindow( GetDesktopWindow(), NULL, 0, - RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN ); - return TRUE; -} - - -HBRUSH STDCALL GetSysColorBrush( INT index ) -{ - if ( bSysColorInit == FALSE ) - SYSCOLOR_Init(); - if (0 <= index && index < NUM_SYS_COLORS) - return SysColorBrushes[index]; - - return GetStockObject(LTGRAY_BRUSH); -} - - -///////////////////////////////////////////////////////////////////////////////////// - -/*********************************************************************** - * GetSysColorPen (Not a Windows API) - * - * This function is new to the Wine lib -- it does not exist in - * Windows. However, it is a natural complement for GetSysColorBrush - * in the Win API and is needed quite a bit inside Wine. - */ -HPEN GetSysColorPen( INT index ) -{ - - if ( bSysColorInit == FALSE ) - SYSCOLOR_Init(); - return SysColorPens[index]; - -} - - -/************************************************************************* - * SYSCOLOR_Init - */ - -void SYSCOLOR_Init(void) -{ - int i, r, g, b; - - for (i = 0; i < NUM_SYS_COLORS; i++) - { - r = DefSysColors[i*3]; - g = DefSysColors[i*3+ 1 ]; - b = DefSysColors[i*3+ 2 ]; - SYSCOLOR_SetColor( i, RGB(r,g,b) ); - } - bSysColorInit = TRUE; -} - -void SYSCOLOR_SetColor( int index, COLORREF color ) -{ - if (index < 0 || index >= NUM_SYS_COLORS) return; - SysColors[index] = color; - if (SysColorBrushes[index]) DeleteObject( SysColorBrushes[index] ); - SysColorBrushes[index] = CreateSolidBrush( color ); - if (SysColorPens[index]) DeleteObject( SysColorPens[index] ); - SysColorPens[index] = CreatePen( PS_SOLID, 1, color ); -} - - - - diff --git a/reactos/lib/user32/graphics/text.c b/reactos/lib/user32/graphics/text.c deleted file mode 100644 index 3ab4c6700c1..00000000000 --- a/reactos/lib/user32/graphics/text.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include - - -int -STDCALL -DrawTextA( - HDC hDC,LPCSTR lpString, - int nCount, LPRECT lpRect, UINT uFormat) -{ - DRAWTEXTPARAMS dtp; - dtp.cbSize = sizeof(DRAWTEXTPARAMS); - dtp.iTabLength = 0; - return TEXT_DrawTextEx(hDC,(void *)lpString, nCount,lpRect,uFormat, &dtp, FALSE); -} - - -int -STDCALL -DrawTextW( - HDC hDC, LPCWSTR lpString, - int nCount, LPRECT lpRect, UINT uFormat) -{ - DRAWTEXTPARAMS dtp; - dtp.cbSize = sizeof(DRAWTEXTPARAMS); - dtp.iTabLength = 0; - return TEXT_DrawTextEx(hDC,(void *)lpString,nCount,lpRect,uFormat, &dtp,TRUE); - -} - -/*********************************************************************** - * GetTabbedTextExtentA (USER32.293) - */ -DWORD -STDCALL -GetTabbedTextExtentA(HDC hDC, LPCSTR lpString, int nCount, int nTabPositions, - LPINT lpnTabStopPositions) -{ - - return TEXT_TabbedTextOutA( hDC, 0, 0, lpString, nCount, nTabPositions, - lpnTabStopPositions,0, FALSE ); -} - - -DWORD -STDCALL -GetTabbedTextExtentW(HDC hDC, LPCWSTR lpString, int nCount, int nTabPositions, - LPINT lpnTabStopPositions) -{ - - return TEXT_TabbedTextOutW( hDC, 0, 0, lpString, nCount, nTabPositions, - lpnTabStopPositions, 0, FALSE ); -} - - -LONG -STDCALL -TabbedTextOutA( HDC hDC, int X, int Y, LPCSTR lpString, - int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) -{ - return TEXT_TabbedTextOutA( hDC, X, Y, lpString, nCount, nTabPositions, - lpnTabStopPositions, nTabOrigin, TRUE ); -} - -LONG -STDCALL -TabbedTextOutW( HDC hDC, int X, int Y, LPCWSTR lpString, - int nCount, int nTabPositions, LPINT lpnTabStopPositions, int nTabOrigin) -{ - return TEXT_TabbedTextOutW( hDC, 0, 0, lpString, nCount, nTabPositions, - lpnTabStopPositions, nTabOrigin, TRUE ); -} - diff --git a/reactos/lib/user32/internal/dce.c b/reactos/lib/user32/internal/dce.c deleted file mode 100644 index c0b8898f175..00000000000 --- a/reactos/lib/user32/internal/dce.c +++ /dev/null @@ -1,440 +0,0 @@ -#include -#define MIN min -#define MAX max - -#include -#include -#include -#include - -DCE *firstDCE = 0; -HDC defaultDCstate = 0; - - -/*********************************************************************** - * REGION_UnionRectWithRgn - * Adds a rectangle to a HRGN32 - * A helper used by scroll.c - */ -WINBOOL REGION_UnionRectWithRgn( HRGN hrgn, const RECT *lpRect ) -{ - - HRGN hRgn; - hRgn = CreateRectRgn(lpRect->left, lpRect->top, lpRect->right, lpRect->bottom); - - CombineRgn(hrgn,hrgn,hRgn, RGN_DIFF); - - return TRUE; -} - - -/*********************************************************************** - * DCE_AllocDCE - * - * Allocate a new DCE. - */ -DCE *DCE_AllocDCE( struct tagWND * wndPtr, DCE_TYPE type ) -{ - DCE * dce; - - - if (!(dce = HeapAlloc( GetProcessHeap(), 0, sizeof(DCE) ))) return NULL; - if (!(dce->hDC = CreateDC( "DISPLAY", NULL, NULL, NULL))) - { - HeapFree( GetProcessHeap(), 0, dce ); - return 0; - } - - - /* store DCE handle in DC hook data field */ - if ( wndPtr != NULL ) { - OffsetWindowOrgEx(dce->hDC,-wndPtr->rectWindow.left, -wndPtr->rectWindow.top, NULL ); - dce->hwndCurrent = wndPtr->hwndSelf; - } - else - dce->hwndCurrent = NULL; - dce->hClipRgn = 0; - dce->next = firstDCE; - firstDCE = dce; - - - FillRect(dce->hDC,&(wndPtr->rectWindow),GetStockObject(GRAY_BRUSH)); - -#if 0 - if( type != DCE_CACHE_DC ) /* owned or class DC */ - { - dce->DCXflags = DCX_DCEBUSY; - if( wndPtr != NULL ) - { - - - if( wndPtr->dwStyle & WS_CLIPCHILDREN ) dce->DCXflags |= DCX_CLIPCHILDREN; - if( wndPtr->dwStyle & WS_CLIPSIBLINGS ) dce->DCXflags |= DCX_CLIPSIBLINGS; - } - //SetHookFlags(dce->hDC,DCHF_INVALIDATEVISRGN); - } - else dce->DCXflags = DCX_CACHE | DCX_DCEEMPTY; -#endif - return dce; -} - - -/*********************************************************************** - * DCE_FreeDCE - */ -DCE* DCE_FreeDCE( DCE *dce ) -{ - DCE **ppDCE = &firstDCE; - - if (!dce) return NULL; - while (*ppDCE && (*ppDCE != dce)) ppDCE = &(*ppDCE)->next; - if (*ppDCE == dce) *ppDCE = dce->next; - - // SetDCHook(dce->hDC, NULL, 0L); - - DeleteDC( dce->hDC ); - if( dce->hClipRgn && !(dce->DCXflags & DCX_KEEPCLIPRGN) ) - DeleteObject(dce->hClipRgn); - HeapFree( GetProcessHeap(), 0, dce ); - return *ppDCE; -} - -/*********************************************************************** - * DCE_DeleteClipRgn - */ -void DCE_DeleteClipRgn( DCE* dce ) -{ - dce->DCXflags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN | DCX_WINDOWPAINT); - - if( dce->DCXflags & DCX_KEEPCLIPRGN ) - dce->DCXflags &= ~DCX_KEEPCLIPRGN; - else - if( dce->hClipRgn > 1 ) - DeleteObject( dce->hClipRgn ); - - dce->hClipRgn = 0; - - //DPRINT("\trestoring VisRgn\n"); - - SelectClipRgn(dce->hDC,NULL); - -} - -/*********************************************************************** - * DCE_GetVisRect - * - * Calculate the visible rectangle of a window (i.e. the client or - * window area clipped by the client area of all ancestors) in the - * corresponding coordinates. Return FALSE if the visible region is empty. - */ -WINBOOL DCE_GetVisRect( WND *wndPtr, WINBOOL clientArea, RECT *lprect ) -{ - *lprect = clientArea ? wndPtr->rectClient : wndPtr->rectWindow; - - if (wndPtr->dwStyle & WS_VISIBLE) - { - INT xoffset = lprect->left; - INT yoffset = lprect->top; - - while (wndPtr->dwStyle & WS_CHILD) - { - wndPtr = wndPtr->parent; - - if ( (wndPtr->dwStyle & (WS_ICONIC | WS_VISIBLE)) != WS_VISIBLE ) - goto fail; - - xoffset += wndPtr->rectClient.left; - yoffset += wndPtr->rectClient.top; - OffsetRect( lprect, wndPtr->rectClient.left, - wndPtr->rectClient.top ); - - if( (wndPtr->rectClient.left >= wndPtr->rectClient.right) || - (wndPtr->rectClient.top >= wndPtr->rectClient.bottom) || - (lprect->left >= wndPtr->rectClient.right) || - (lprect->right <= wndPtr->rectClient.left) || - (lprect->top >= wndPtr->rectClient.bottom) || - (lprect->bottom <= wndPtr->rectClient.top) ) - goto fail; - - lprect->left = MAX( lprect->left, wndPtr->rectClient.left ); - lprect->right = MIN( lprect->right, wndPtr->rectClient.right ); - lprect->top = MAX( lprect->top, wndPtr->rectClient.top ); - lprect->bottom = MIN( lprect->bottom, wndPtr->rectClient.bottom ); - } - OffsetRect( lprect, -xoffset, -yoffset ); - return TRUE; - } - -fail: - SetRectEmpty( lprect ); - return FALSE; -} - - -/*********************************************************************** - * DCE_AddClipRects - * - * Go through the linked list of windows from pWndStart to pWndEnd, - * adding to the clip region the intersection of the target rectangle - * with an offset window rectangle. - */ -WINBOOL DCE_AddClipRects( WND *pWndStart, WND *pWndEnd, - HRGN hrgnClip, LPRECT lpRect, int x, int y ) -{ - RECT rect; - -// if( pWndStart->pDriver->pIsSelfClipping( pWndStart ) ) - // return TRUE; /* The driver itself will do the clipping */ - - for (; pWndStart != pWndEnd; pWndStart = pWndStart->next) - { - if( !(pWndStart->dwStyle & WS_VISIBLE) ) continue; - - rect.left = pWndStart->rectWindow.left + x; - rect.top = pWndStart->rectWindow.top + y; - rect.right = pWndStart->rectWindow.right + x; - rect.bottom = pWndStart->rectWindow.bottom + y; - - if( IntersectRect( &rect, &rect, lpRect )) - if(!REGION_UnionRectWithRgn( hrgnClip, &rect )) - break; - } - return (pWndStart == pWndEnd); -} - - - -/*********************************************************************** - * DCE_GetVisRgn - * - * Return the visible region of a window, i.e. the client or window area - * clipped by the client area of all ancestors, and then optionally - * by siblings and children. - */ -HRGN DCE_GetVisRgn( HWND hwnd, WORD flags ) -{ - HRGN hrgnVis = 0; - RECT rect; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - /* Get visible rectangle and create a region with it. */ - - if (wndPtr && DCE_GetVisRect(wndPtr, !(flags & DCX_WINDOW), &rect)) - { - if((hrgnVis = CreateRectRgnIndirect( &rect ))) - { - HRGN hrgnClip = CreateRectRgn( 0, 0, 0, 0 ); - INT xoffset, yoffset; - - if( hrgnClip ) - { - /* Compute obscured region for the visible rectangle by - * clipping children, siblings, and ancestors. Note that - * DCE_GetVisRect() returns a rectangle either in client - * or in window coordinates (for DCX_WINDOW request). */ - - if( (flags & DCX_CLIPCHILDREN) && wndPtr->child ) - { - if( flags & DCX_WINDOW ) - { - /* adjust offsets since child window rectangles are - * in client coordinates */ - - xoffset = wndPtr->rectClient.left - wndPtr->rectWindow.left; - yoffset = wndPtr->rectClient.top - wndPtr->rectWindow.top; - } - else - xoffset = yoffset = 0; - - DCE_AddClipRects( wndPtr->child, NULL, hrgnClip, - &rect, xoffset, yoffset ); - } - - /* sibling window rectangles are in client - * coordinates of the parent window */ - - if (flags & DCX_WINDOW) - { - xoffset = -wndPtr->rectWindow.left; - yoffset = -wndPtr->rectWindow.top; - } - else - { - xoffset = -wndPtr->rectClient.left; - yoffset = -wndPtr->rectClient.top; - } - - if (flags & DCX_CLIPSIBLINGS && wndPtr->parent ) - DCE_AddClipRects( wndPtr->parent->child, - wndPtr, hrgnClip, &rect, xoffset, yoffset ); - - /* Clip siblings of all ancestors that have the - * WS_CLIPSIBLINGS style - */ - - while (wndPtr->dwStyle & WS_CHILD) - { - wndPtr = wndPtr->parent; - xoffset -= wndPtr->rectClient.left; - yoffset -= wndPtr->rectClient.top; - if(wndPtr->dwStyle & WS_CLIPSIBLINGS && wndPtr->parent) - { - DCE_AddClipRects( wndPtr->parent->child, wndPtr, - hrgnClip, &rect, xoffset, yoffset ); - } - } - - /* Now once we've got a jumbo clip region we have - * to substract it from the visible rectangle. - */ - - CombineRgn( hrgnVis, hrgnVis, hrgnClip, RGN_DIFF ); - DeleteObject( hrgnClip ); - } - else - { - DeleteObject( hrgnVis ); - hrgnVis = 0; - } - } - } - else - hrgnVis = CreateRectRgn(0, 0, 0, 0); /* empty */ - return hrgnVis; -} - -/*********************************************************************** - * DCE_OffsetVisRgn - * - * Change region from DC-origin relative coordinates to screen coords. - */ - -void DCE_OffsetVisRgn( HDC hDC, HRGN hVisRgn ) -{ -/* - DC *dc; - if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return; - - OffsetRgn( hVisRgn, dc->w.DCOrgX, dc->w.DCOrgY ); - - GDI_HEAP_UNLOCK( hDC ); -*/ -} - - - -/*********************************************************************** - * DCE_ExcludeRgn - * - * Translate given region from the wnd client to the DC coordinates - * and add it to the clipping region. - */ -INT DCE_ExcludeRgn( HDC hDC, WND* wnd, HRGN hRgn ) -{ - POINT pt = {0, 0}; - DCE *dce = firstDCE; - - while (dce && (dce->hDC != hDC)) dce = dce->next; - if( dce ) - { - MapWindowPoints( wnd->hwndSelf, dce->hwndCurrent, &pt, 1); - if( dce->DCXflags & DCX_WINDOW ) - { - wnd = WIN_FindWndPtr(dce->hwndCurrent); - pt.x += wnd->rectClient.left - wnd->rectWindow.left; - pt.y += wnd->rectClient.top - wnd->rectWindow.top; - } - } - else return ERROR; - OffsetRgn(hRgn, pt.x, pt.y); - - return ExtSelectClipRgn( hDC, hRgn, RGN_DIFF ); -} - -/*********************************************************************** - * DCE_InvalidateDCE - * - * It is called from SetWindowPos() - we have to mark as dirty all busy - * DCE's for windows that have pWnd->parent as an ansector and whose client - * rect intersects with specified update rectangle. - */ -WINBOOL DCE_InvalidateDCE(WND* pWnd, const RECT* pRectUpdate) -{ - WND* wndScope = pWnd->parent; - WINBOOL bRet = FALSE; - - if( wndScope ) - { - DCE *dce; - - DPRINT("scope hwnd = %04x, (%i,%i - %i,%i)\n", - wndScope->hwndSelf, pRectUpdate->left,pRectUpdate->top, - pRectUpdate->right,pRectUpdate->bottom); -// if(TRACE_ON(dc)) -// DCE_DumpCache(); - - /* walk all DCEs and fixup non-empty entries */ - - for (dce = firstDCE; (dce); dce = dce->next) - { - if( !(dce->DCXflags & DCX_DCEEMPTY) ) - { - WND* wndCurrent = WIN_FindWndPtr(dce->hwndCurrent); - - if( wndCurrent && wndCurrent != WIN_GetDesktop() ) - { - WND* wnd = wndCurrent; - INT xoffset = 0, yoffset = 0; - - if( (wndCurrent == wndScope) && !(dce->DCXflags & DCX_CLIPCHILDREN) ) continue; - - /* check if DCE window is within the z-order scope */ - - for( wnd = wndCurrent; wnd; wnd = wnd->parent ) - { - if( wnd == wndScope ) - { - RECT wndRect; - - wndRect = wndCurrent->rectWindow; - - OffsetRect( &wndRect, xoffset - wndCurrent->rectClient.left, - yoffset - wndCurrent->rectClient.top); - - if (pWnd == wndCurrent || - IntersectRect( &wndRect, &wndRect, pRectUpdate )) - { - if( !(dce->DCXflags & DCX_DCEBUSY) ) - { - /* Don't bother with visible regions of unused DCEs */ - - DPRINT("\tpurged %08x dce [%04x]\n", - (unsigned)dce, wndCurrent->hwndSelf); - - dce->hwndCurrent = 0; - dce->DCXflags &= DCX_CACHE; - dce->DCXflags |= DCX_DCEEMPTY; - } - else - { - /* Set dirty bits in the hDC and DCE structs */ - - DPRINT("\tfixed up %08x dce [%04x]\n", - (unsigned)dce, wndCurrent->hwndSelf); - - dce->DCXflags |= DCX_DCEDIRTY; - //SetHookFlags(dce->hDC, DCHF_INVALIDATEVISRGN); - bRet = TRUE; - } - } - break; - } - xoffset += wnd->rectClient.left; - yoffset += wnd->rectClient.top; - } - } - } - } /* dce list */ - } - return bRet; -} diff --git a/reactos/lib/user32/internal/defwnd.c b/reactos/lib/user32/internal/defwnd.c deleted file mode 100644 index 96ed48c7ddd..00000000000 --- a/reactos/lib/user32/internal/defwnd.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Default window procedure - * - * Copyright 1993, 1996 Alexandre Julliard - * 1995 Alex Korobka - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - - -#define WM_CTLCOLOR 0x0019 -#define WM_ISACTIVEICON 0x0035 -#define WM_DROPOBJECT 0x022A -#define WM_QUERYDROPOBJECT 0x022B - -#define DRAG_FILE 0x454C4946 - - /* Last COLOR id */ -#define COLOR_MAX COLOR_BTNHIGHLIGHT - - /* bits in the dwKeyData */ -#define KEYDATA_ALT 0x2000 -#define KEYDATA_PREVSTATE 0x4000 - -static short iF10Key = 0; -static short iMenuSysKey = 0; - -/*********************************************************************** - * DEFWND_HandleWindowPosChanged - * - * Handle the WM_WINDOWPOSCHANGED message. - */ -void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags ) -{ - WPARAM wp = SIZE_RESTORED; - - if (!(flags & SWP_NOCLIENTMOVE)) - SendMessage( wndPtr->hwndSelf, WM_MOVE, 0, - MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top)); - if (!(flags & SWP_NOCLIENTSIZE)) - { - if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED; - else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED; - - SendMessage( wndPtr->hwndSelf, WM_SIZE, wp, - MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left, - wndPtr->rectClient.bottom-wndPtr->rectClient.top)); - } -} - - -/*********************************************************************** - * DEFWND_SetText - * - * Set the window text. - */ - -void DEFWND_SetText( WND *wndPtr,const void *text ) -{ - if ( wndPtr->class->bUnicode ) - DEFWND_SetTextW( wndPtr, (LPCWSTR) text ); - else - DEFWND_SetTextA( wndPtr, (LPCSTR) text ); - -} - -void DEFWND_SetTextA( WND *wndPtr, LPCSTR text ) -{ - if (!text) text = ""; - if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text ); - wndPtr->text = (void *)HEAP_strdupA( GetProcessHeap(), 0, text ); - if ( wndPtr->dwStyle & WS_CAPTION ) - NC_HandleNCPaint( wndPtr->hwndSelf , (HRGN)1 ); /* Repaint caption */ - - -} - - -void DEFWND_SetTextW( WND *wndPtr, LPCWSTR text ) -{ - if (!text) text = L""; - if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text ); - wndPtr->text = (void *)HEAP_strdupW( GetProcessHeap(), 0, text ); - if ( wndPtr->dwStyle & WS_CAPTION ) - NC_HandleNCPaint( wndPtr->hwndSelf , (HRGN)1 ); /* Repaint caption */ - -} -/*********************************************************************** - * DEFWND_ControlColor - * - * Default colors for control painting. - */ -HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType ) -{ - if( ctlType == CTLCOLOR_SCROLLBAR) - { - HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR); - SetBkColor( hDC, RGB(255, 255, 255) ); - SetTextColor( hDC, RGB(0, 0, 0) ); - UnrealizeObject( hb ); - return hb; - } - - SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT)); - - if (TWEAK_WineLook > WIN31_LOOK) { - if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX)) - SetBkColor( hDC, GetSysColor(COLOR_WINDOW) ); - else { - SetBkColor( hDC, GetSysColor(COLOR_3DFACE) ); - return GetSysColorBrush(COLOR_3DFACE); - } - } - else - SetBkColor( hDC, GetSysColor(COLOR_WINDOW) ); - return GetSysColorBrush(COLOR_WINDOW); -} - - -/*********************************************************************** - * DEFWND_SetRedraw - */ -void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam ) -{ - WINBOOL bVisible = wndPtr->dwStyle & WS_VISIBLE; - - DPRINT("%04x %i\n", (UINT)wndPtr->hwndSelf, (wParam!=0) ); - - if( wParam ) - { - if( !bVisible ) - { - //wndPtr->dwStyle |= WS_VISIBLE; - DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow ); - } - } - else if( bVisible ) - { - if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE; - else wParam = RDW_ALLCHILDREN | RDW_VALIDATE; - - PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 ); - DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow ); -// wndPtr->dwStyle &= ~WS_VISIBLE; - } -} - -/*********************************************************************** - * DEFWND_DefWinProc - * - * Default window procedure for messages that are the same in Win and Win. - */ -LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam, - LPARAM lParam ) -{ - POINT pt; - switch(msg) - { - case WM_NCPAINT: - return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam ); - - case WM_NCHITTEST: - pt.x = LOWORD(lParam); - pt.y = HIWORD(lParam); - return NC_HandleNCHitTest( wndPtr->hwndSelf, pt); - - case WM_NCLBUTTONDOWN: - return NC_HandleNCLButtonDown( wndPtr, wParam, lParam ); - - case WM_LBUTTONDBLCLK: - case WM_NCLBUTTONDBLCLK: - return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam ); - - case WM_RBUTTONDOWN: - case WM_NCRBUTTONDOWN: - if ((wndPtr->flags & WIN_ISWIN) || (TWEAK_WineLook > WIN31_LOOK)) - { - ClientToScreen(wndPtr->hwndSelf, (LPPOINT)&lParam); - MSG_SendMessage( wndPtr, WM_CONTEXTMENU, - (WPARAM)wndPtr->hwndSelf,(LPARAM) lParam); - } - break; - - case WM_CONTEXTMENU: - if( wndPtr->dwStyle & WS_CHILD ) - SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam ); - else - if (wndPtr->hSysMenu) - { /* - TrackPopupMenu(wndPtr->hSysMenu,TPM_LEFTALIGN | TPM_RETURNCMD,LOWORD(lParam),HIWORD(lParam),0,wndPtr->hwndSelf,NULL); - DestroyMenu(wndPtr->hSysMenu); - */ - DPRINT("Fixme Display default popup menu\n"); - /* Track system popup if click was in the caption area. */ - } - break; - - case WM_NCACTIVATE: - return NC_HandleNCActivate( wndPtr, wParam ); - - case WM_NCDESTROY: - if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text ); - wndPtr->text = NULL; - if (wndPtr->pVScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll ); - if (wndPtr->pHScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll ); - wndPtr->pVScroll = wndPtr->pHScroll = NULL; - return 0; - - case WM_PAINTICON: - case WM_PAINT: - { - PAINTSTRUCT ps; - HDC hdc = BeginPaint( wndPtr->hwndSelf, &ps ); - if( hdc ) - { - if( (wndPtr->dwStyle & WS_MINIMIZE) && wndPtr->class->hIcon ) - { - int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left - - SYSMETRICS_CXICON)/2; - int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top - - SYSMETRICS_CYICON)/2; - DPRINT("Painting class icon: vis rect=(%i,%i - %i,%i)\n", - ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom ); - DrawIcon( hdc, x, y, wndPtr->class->hIcon ); - } - EndPaint( wndPtr->hwndSelf, &ps ); - } - return 0; - } - - case WM_SETREDRAW: - DEFWND_SetRedraw( wndPtr, wParam ); - return 0; - - case WM_CLOSE: - DestroyWindow( wndPtr->hwndSelf ); - return 0; - - case WM_MOUSEACTIVATE: - if (wndPtr->dwStyle & WS_CHILD) - { - LONG ret = SendMessage( wndPtr->parent->hwndSelf, - WM_MOUSEACTIVATE, wParam, lParam ); - if (ret) return ret; - } - - /* Caption clicks are handled by the NC_HandleNCLButtonDown() */ - return (LOWORD(lParam) == HTCAPTION) ? MA_NOACTIVATE : MA_ACTIVATE; - - case WM_ACTIVATE: - if (LOWORD(wParam) != WA_INACTIVE) - SetWindowPos(wndPtr->hwndSelf, HWND_TOP, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE); - break; - - case WM_ERASEBKGND: - case WM_ICONERASEBKGND: - { - if (!wndPtr->class->hbrBackground) return 0; - - if (wndPtr->class->hbrBackground <= (HBRUSH)(COLOR_MAX+1)) - { - HBRUSH hbrush = CreateSolidBrush( - GetSysColor(((DWORD)wndPtr->class->hbrBackground)-1)); - FillWindow( GetParent(wndPtr->hwndSelf), wndPtr->hwndSelf, - (HDC)wParam, hbrush); - DeleteObject( hbrush ); - } - else FillWindow( GetParent(wndPtr->hwndSelf), wndPtr->hwndSelf, - (HDC)wParam, wndPtr->class->hbrBackground ); - return 1; - } - - case WM_GETDLGCODE: - return 0; - - case WM_CTLCOLORMSGBOX: - case WM_CTLCOLOREDIT: - case WM_CTLCOLORLISTBOX: - case WM_CTLCOLORBTN: - case WM_CTLCOLORDLG: - case WM_CTLCOLORSTATIC: - case WM_CTLCOLORSCROLLBAR: - return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX ); - - case WM_CTLCOLOR: - return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) ); - - case WM_GETTEXTLENGTH: - if (wndPtr->text && wndPtr->class->bUnicode == TRUE) - return (LRESULT)lstrlenW(wndPtr->text); - else if (wndPtr->text && wndPtr->class->bUnicode == FALSE) - return (LRESULT)lstrlenA(wndPtr->text); - return 0; - - case WM_SETCURSOR: - if (wndPtr->dwStyle & WS_CHILD) - if (SendMessage(wndPtr->parent->hwndSelf, WM_SETCURSOR, - wParam, lParam)) - return TRUE; - return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam ); - - case WM_SYSCOMMAND: - pt.x = LOWORD(lParam); - pt.y = HIWORD(lParam); - return NC_HandleSysCommand( wndPtr->hwndSelf, wParam,pt); - - case WM_KEYDOWN: - if(wParam == VK_F10) iF10Key = VK_F10; - break; - - case WM_SYSKEYDOWN: - if( HIWORD(lParam) & KEYDATA_ALT ) - { - /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */ - if( wParam == VK_MENU && !iMenuSysKey ) - iMenuSysKey = 1; - else - iMenuSysKey = 0; - - iF10Key = 0; - - if( wParam == VK_F4 ) /* try to close the window */ - { - HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf ); - wndPtr = WIN_FindWndPtr( hWnd ); - if( wndPtr && !(wndPtr->class->style & CS_NOCLOSE) ) - PostMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 ); - } - } - else if( wParam == VK_F10 ) - iF10Key = 1; - else - if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000)) - SendMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, - (WPARAM)SC_KEYMENU, (LPARAM)VK_SPACE); - break; - - case WM_KEYUP: - case WM_SYSKEYUP: - /* Press and release F10 or ALT */ - if (((wParam == VK_MENU) && iMenuSysKey) || - ((wParam == VK_F10) && iF10Key)) - SendMessage( WIN_GetTopParent(wndPtr->hwndSelf), - WM_SYSCOMMAND, SC_KEYMENU, 0L ); - iMenuSysKey = iF10Key = 0; - break; - - case WM_SYSCHAR: - iMenuSysKey = 0; - if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE)) - { - PostMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, - (WPARAM)SC_RESTORE, 0L ); - break; - } - if ((HIWORD(lParam) & KEYDATA_ALT) && wParam) - { - if (wParam == VK_TAB || wParam == VK_ESCAPE) break; - if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD)) - SendMessage( wndPtr->parent->hwndSelf, msg, wParam, lParam ); - else - SendMessage( wndPtr->hwndSelf, WM_SYSCOMMAND, - (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)wParam ); - } - else /* check for Ctrl-Esc */ - if (wParam != VK_ESCAPE) MessageBeep(0); - break; - - case WM_SHOWWINDOW: - if (!lParam) return 0; /* sent from ShowWindow */ - if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0; - if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0; - else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0; - ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE ); - break; - - case WM_CANCELMODE: - //if (wndPtr->parent == WIN_GetDesktop()) - //EndMenu(); - if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture(); - break; - - case WM_VKEYTOITEM: - case WM_CHARTOITEM: - return -1; - - case WM_DROPOBJECT: - return DRAG_FILE; - - case WM_QUERYDROPOBJECT: - if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1; - break; - - case WM_QUERYDRAGICON: - { -#if 0 - HICON hIcon=0; - UINT len; - - if( (hIcon=wndPtr->class->hCursor) ) return (LRESULT)hIcon; - for(len=1; len<64; len++) - if((hIcon=LoadIcon(wndPtr->hInstance,MAKEINTRESOURCE(len)))) - return (LRESULT)hIcon; - return (LRESULT)LoadIcon(0,IDI_APPLICATION); - -#endif - } - return 0; - break; - - case WM_ISACTIVEICON: - return ((wndPtr->flags & WIN_NCACTIVATED) != 0); - - case WM_QUERYOPEN: - case WM_QUERYENDSESSION: - return 1; - } - return 0; -} - - - - diff --git a/reactos/lib/user32/internal/dialog.c b/reactos/lib/user32/internal/dialog.c deleted file mode 100644 index 6883f5a94bf..00000000000 --- a/reactos/lib/user32/internal/dialog.c +++ /dev/null @@ -1,1005 +0,0 @@ -/* - * Dialog functions - * - * Copyright 1993, 1994, 1996 Alexandre Julliard - */ - -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS system libraries - * FILE: lib/user32/internal/dialog.c - * PURPOSE: Reads resources and creates dialogs - * PROGRAMER: Boudewijn Dekker - * UPDATE HISTORY: - * 09/09/99: Modified - * TODO Fixup fonts and fonts and text metrics - Warnings - references to libc - */ - -#include -#include -#include -#include - -#define UNICODE -#include -#include -#include -#include -#include -#include -#include -#include - - - - /* Dialog base units */ -WORD xBaseUnit = 0, yBaseUnit = 0; - - -/*********************************************************************** - * DIALOG_Init - * - * Initialisation of the dialog manager. - */ -WINBOOL DIALOG_Init(void) -{ - TEXTMETRIC tm; - HDC hdc; - - /* Calculate the dialog base units */ - - if (!(hdc = CreateDC( L"DISPLAY", NULL, NULL, NULL ))) return FALSE; - GetTextMetrics( hdc, &tm ); - DeleteDC( hdc ); - xBaseUnit = tm.tmAveCharWidth; - yBaseUnit = tm.tmHeight; - - /* Dialog units are based on a proportional system font */ - /* so we adjust them a bit for a fixed font. */ - if (!(tm.tmPitchAndFamily & TMPF_FIXED_PITCH)) - xBaseUnit = xBaseUnit * 5 / 4; - - return TRUE; -} - -/*********************************************************************** - * DIALOG_DoDialogBox - */ -INT DIALOG_DoDialogBox( HWND hwnd, HWND owner ) -{ - WND * wndPtr; - DIALOGINFO * dlgInfo; - MSG msg; - INT retval; - - /* Owner must be a top-level window */ - owner = WIN_GetTopParent( owner ); - if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1; - dlgInfo = (DIALOGINFO *)wndPtr->wExtra; - EnableWindow( owner, FALSE ); - ShowWindow( hwnd, SW_SHOW ); - - while (MSG_InternalGetMessage(&msg, hwnd, owner, MSGF_DIALOGBOX, PM_REMOVE, - !(wndPtr->dwStyle & DS_NOIDLEMSG) )) - { - if (!IsDialogMessage( hwnd, &msg)) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - if (dlgInfo->flags & DF_END) break; - } - retval = dlgInfo->idResult; - EnableWindow( owner, TRUE ); - dlgInfo->flags |= DF_ENDING; /* try to stop it being destroyed twice */ - DestroyWindow( hwnd ); - return retval; -} - - - -/*********************************************************************** - * DIALOG_ParseTemplate - * - * Fill a DLG_TEMPLATE structure from the dialog template, and return - * a pointer to the first control. - */ -LPCDLGITEMTEMPLATE DIALOG_ParseTemplate( LPCDLGTEMPLATE DlgTemplate, DLG_TEMPLATE * result, WINBOOL bUnicode ) -{ - WORD *p; - - - result->dialogEx = FALSE; - result->helpId = 0; - result->exStyle = DlgTemplate->dwExtendedStyle; - - result->nbItems = DlgTemplate->cdit; - result->x = DlgTemplate->x; - result->y = DlgTemplate->y; - result->cx = DlgTemplate->cx; - result->cy = DlgTemplate->cy; - - DPRINT("%d %d %d %d\n",result->x, result->y, result->cx, result->cy); - - - p = &(DlgTemplate->cy); - p++; - - - /* Get the menu name */ - - switch((WORD)*p) - { - case 0x0000: - result->menuName = NULL; - p++; - break; - case 0xffff: - p++; - result->menuName = (LPWSTR) *p; // Ordinal of Menu resource - p++; - break; - default: - result->menuName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ); - p++; - break; - } - - /* Get the class name */ - - - - switch((WORD)*p) - { - case 0x0000: - if ( bUnicode == TRUE ) - result->className = DIALOG_CLASS_NAMEW; - else - result->className = DIALOG_CLASS_NAMEA; - p++; - break; - case 0xffff: - p++; - result->className = (LPCWSTR)p; // Ordinal of predefined class - p++; - break; - default: - result->className = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ); - p++; - break; - } - - result->caption = L""; - - /* Get the window caption */ - if ( *p != 0 ) { - result->caption = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - - - /* Get the font name */ - - if (result->style & DS_SETFONT) - { - result->pointSize = *p; - p++; - if (result->dialogEx) - { - result->weight = *p; p++; - result->italic = LOBYTE(*p); p++; - } - else - { - result->weight = FW_DONTCARE; - result->italic = FALSE; - } - result->faceName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - - } - } - else if ( *(p+1) != 0 ) { - p++; - - /* Get the font name */ - - if (result->style & DS_SETFONT) - { - result->pointSize = *p; - p++; - if (result->dialogEx) - { - result->weight = *p; p++; - result->italic = LOBYTE(*p); p++; - } - else - { - result->weight = FW_DONTCARE; - result->italic = FALSE; - } - result->faceName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - - } - } - - - - - /* First control is on dword boundary */ - return (LPCDLGITEMTEMPLATE )((((int)p) + 3) & ~3); -} - -/*********************************************************************** - * DIALOG_ParseTemplate - * - * Fill a DLG_TEMPLATE structure from the dialog template, and return - * a pointer to the first control. - */ -LPCDLGITEMTEMPLATEEX DIALOG_ParseTemplateEx( LPCDLGTEMPLATEEX DlgTemplate, DLG_TEMPLATE * result,WINBOOL bUnicode ) -{ - WORD *p; - - - result->dialogEx = TRUE; - result->helpId = DlgTemplate->helpID; - result->exStyle = DlgTemplate->exStyle; - result->style = DlgTemplate->style; - - result->nbItems = DlgTemplate->cDlgItems; - result->x = DlgTemplate->x; - result->y = DlgTemplate->y; - result->cx = DlgTemplate->cx; - result->cy = DlgTemplate->cy; - - p = &(DlgTemplate->cy); - p++; - - /* Get the menu name */ - - switch(*p) - { - case 0x0000: - result->menuName = NULL; - p++; - break; - case 0xffff: - p++; - result->menuName = (LPCWSTR)(WORD)*( p ); // Ordinal of Menu resource - p++; - break; - default: - result->menuName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - break; - } - - /* Get the class name */ - - switch(*p) - { - case 0x0000: - if ( bUnicode == TRUE ) - result->className = DIALOG_CLASS_NAMEW; - else - result->className = DIALOG_CLASS_NAMEA; - p++; - break; - case 0xffff: - p++; - result->className = (LPCWSTR)(WORD)*( p ); - p ++; - DPRINT( " CLASS %04x\n", LOWORD(result->className) ); - break; - default: - result->className = (LPCWSTR)p; - DPRINT( " CLASS %s\n", debugstr_w( (LPCWSTR)p )); - p += lstrlenW( (LPCWSTR)p ) + 1; - break; - } - - - result->caption = L""; - - /* Get the window caption */ - if ( *p != 0 ) { - result->caption = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - - - /* Get the font name */ - - if (result->style & DS_SETFONT) - { - result->pointSize = *p; - p++; - if (result->dialogEx) - { - result->weight = *p; p++; - result->italic = LOBYTE(*p); p++; - } - else - { - result->weight = FW_DONTCARE; - result->italic = FALSE; - } - result->faceName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - - } - } - else if ( *(p+1) != 0 ) { - p++; - - /* Get the font name */ - - if (result->style & DS_SETFONT) - { - result->pointSize = LOWORD(p); - p++; - if (result->dialogEx) - { - result->weight = *p; p++; - result->italic = LOBYTE(*p); p++; - } - else - { - result->weight = FW_DONTCARE; - result->italic = FALSE; - } - result->faceName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - - } - } - - - /* First control is on dword boundary */ - return (LPDLGITEMTEMPLATEEX )((((int)p) + 3) & ~3); -} - - -/*********************************************************************** - * DIALOG_GetControl - * - * Return the class and text of the control pointed to by ptr, - * fill the header structure and return a pointer to the next control. - */ -LPCDLGITEMTEMPLATE DIALOG_GetControl( LPCDLGITEMTEMPLATE DlgItemTemplate, DLG_CONTROL_INFO *info) -{ - WORD *p; - WORD id; - - info->helpId = 0; - info->exStyle = DlgItemTemplate->dwExtendedStyle; - info->style = DlgItemTemplate->style; - - info->x = DlgItemTemplate->x; - info->y = DlgItemTemplate->y; - info->cx = DlgItemTemplate->cx; - info->cy = DlgItemTemplate->cy; - - - info->id = DlgItemTemplate->id; - - - p = (char *)DlgItemTemplate + sizeof(DLGITEMTEMPLATE); - p--; - - if (*p == 0xffff) - { - - static const WCHAR class_names[6][10] = - { - { BUTTON_CLASS_NAME }, /* 0x80 */ - { EDIT_CLASS_NAME }, /* 0x81 */ - { STATIC_CLASS_NAME }, /* 0x82 */ - { LISTBOX_CLASS_NAME}, /* 0x83 */ - { SCROLLBAR_CLASS_NAME }, /* 0x84 */ - { COMBOBOX_CLASS_NAME } /* 0x85 */ - }; - p++; - id = (WORD)*(p); - if ((id >= 0x80) && (id <= 0x85)) - info->className = (LPCSTR)HEAP_strdupW(GetProcessHeap(),0,class_names[id - 0x80]); - else - info->className = NULL; - p++; - } - else - { - info->className = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - } - - if (*p == 0xffff) /* Is it an integer id? */ - { - p++; - info->windowName = (LPCWSTR)(WORD)*(p + 1); - p++; - } - else - { - info->windowName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - } - - - - if (*p) - { - p++; - info->data = (LPVOID)(p); - p += *p / sizeof(WORD); - } - else { - info->data = NULL; - p++; - } - - /* Next control is on dword boundary */ - return (LPCDLGITEMTEMPLATE)((((int)p) + 3) & ~3); -} - - -/*********************************************************************** - * DIALOG_GetControl - * - * Return the class and text of the control pointed to by ptr, - * fill the header structure and return a pointer to the next control. - */ -LPCDLGITEMTEMPLATEEX DIALOG_GetControlEx( LPCDLGITEMTEMPLATEEX DlgItemTemplate, DLG_CONTROL_INFO *info ) -{ - WORD *p; - WORD id; - info->helpId = DlgItemTemplate->helpID; - info->exStyle = DlgItemTemplate->exStyle; - info->style = DlgItemTemplate->style; - - info->x = DlgItemTemplate->x; - info->y = DlgItemTemplate->y; - info->cx = DlgItemTemplate->cx; - info->cy = DlgItemTemplate->cy; - - - /* id is a DWORD for DIALOGEX */ - info->id = DlgItemTemplate->id; - - p = (char *)DlgItemTemplate + sizeof(DLGITEMTEMPLATEEX); - p--; - - if (*p == 0xffff) - { - - static const WCHAR class_names[6][10] = - { - { BUTTON_CLASS_NAME }, /* 0x80 */ - { EDIT_CLASS_NAME }, /* 0x81 */ - { STATIC_CLASS_NAME }, /* 0x82 */ - { LISTBOX_CLASS_NAME}, /* 0x83 */ - { SCROLLBAR_CLASS_NAME }, /* 0x84 */ - { COMBOBOX_CLASS_NAME } /* 0x85 */ - }; - p++; - id = (WORD)*(p); - if ((id >= 0x80) && (id <= 0x85)) - info->className = (LPCSTR)HEAP_strdupW(GetProcessHeap(),0,class_names[id - 0x80]); - else - info->className = NULL; - - p++; - } - else - { - info->className = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - } - - if (*p == 0xffff) /* Is it an integer id? */ - { - p++; - info->windowName = (LPCWSTR)(WORD)*(p); - p++; - } - else - { - - info->windowName = (LPCWSTR)p; - p += lstrlenW( (LPCWSTR)p ) + 1; - } - - - - if (*p) { - - p++; - info->data = (LPVOID)(p); - p += *p / sizeof(WORD); - } - else { - info->data = NULL; - p++; - } - - /* Next control is on dword boundary */ - return (LPCDLGITEMTEMPLATE)((((int)p) + 3) & ~3); -} - - -/*********************************************************************** - * DIALOG_CreateControls - * - * Create the control windows for a dialog. - */ -WINBOOL DIALOG_CreateControls( HANDLE hWndDialog, DIALOGINFO *dlgInfo , - void *template, INT items, - HINSTANCE hInst, WINBOOL bDialogEx) -{ - DLG_CONTROL_INFO info; - HWND hwndCtrl, hwndDefButton = 0; - - while (items--) - { - - if ( bDialogEx) - template = (void *)DIALOG_GetControlEx( (LPDLGITEMTEMPLATEEX)template, &info ); - else - template = (void *)DIALOG_GetControl( (LPDLGITEMTEMPLATE)template, &info ); - - - - hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY, - (LPCWSTR)info.className, - (LPCWSTR)info.windowName, - info.style | WS_CHILD | WS_VISIBLE , - info.x * dlgInfo->xBaseUnit / 4, - info.y * dlgInfo->yBaseUnit / 4, - info.cx * dlgInfo->xBaseUnit / 4, - info.cy * dlgInfo->yBaseUnit / 4, - hWndDialog, (HMENU)info.id, - hInst, info.data ); - - - if (hwndCtrl) { - - /* Send initialisation messages to the control */ - if (dlgInfo->hUserFont) SendMessage( hwndCtrl, WM_SETFONT, - (WPARAM)dlgInfo->hUserFont, 0 ); - if (SendMessage(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON) - { - /* If there's already a default push-button, set it back */ - /* to normal and use this one instead. */ - if (hwndDefButton) - SendMessage( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON,FALSE ); - hwndDefButton = hwndCtrl; - dlgInfo->idResult = GetWindowLong( hwndCtrl, GWL_ID ); - } - - - } - } - return TRUE; -} - - - - - -/*********************************************************************** - * DIALOG_CreateIndirect - */ -HWND DIALOG_CreateIndirect( HINSTANCE hInst, void *dlgTemplate, HWND owner, - DLGPROC dlgProc, LPARAM param, - WINBOOL bUnicode ) -{ - HMENU hMenu = 0; - HFONT hFont = 0; - HWND hwnd; - RECT rect; - WND * wndPtr; - DLG_TEMPLATE template; - DIALOGINFO * dlgInfo; - WORD xUnit = xBaseUnit; - WORD yUnit = yBaseUnit; - void *dlgItemTemplate; - - - - if ( xBaseUnit == 0 ) - DIALOG_Init(); - - xUnit = xBaseUnit; - yUnit = yBaseUnit; - - - - /* Parse dialog template */ - - - if (((LPDLGTEMPLATEEX)dlgTemplate)->signature != 0xffff) /* DIALOGEX resource */ - dlgItemTemplate = (void *)DIALOG_ParseTemplate((LPCDLGTEMPLATE) dlgTemplate, &template, bUnicode ); - else - dlgItemTemplate = (void *)DIALOG_ParseTemplateEx( (LPCDLGTEMPLATEEX)dlgTemplate, &template, bUnicode ); - - - /* Load menu */ - if (template.menuName) - hMenu = LoadMenuW( hInst, (LPCWSTR)template.menuName ); - - - /* Create custom font if needed */ - - if (template.style & DS_SETFONT) - { - /* The font height must be negative as it is a point size */ - /* (see CreateFont() documentation in the Windows SDK). */ - - - hFont = CreateFontW( -template.pointSize, 0, 0, 0, - template.weight, template.italic, FALSE, - FALSE, DEFAULT_CHARSET, 0, 0, PROOF_QUALITY, - FF_DONTCARE, (LPCWSTR)template.faceName ); - - - if (hFont) - { - TEXTMETRIC tm; - HFONT oldFont; - HDC hdc; - /* Calculate the dialog base units */ - - hdc = CreateDC( L"DISPLAY", NULL, NULL, NULL ); - SelectObject( hdc, hFont ); - GetTextMetrics( hdc, &tm ); - DeleteDC( hdc ); - - - xUnit = tm.tmAveCharWidth; - yUnit = tm.tmHeight; - if (!(tm.tmPitchAndFamily & TMPF_FIXED_PITCH)) - xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */ - - } - - } - - - /* Create dialog main window */ - - rect.left = rect.top = 0; - rect.right = template.cx * xUnit / 4; - rect.bottom = template.cy * yUnit / 8; - - //rect.left = template.x; - //rect.top = template.y; - - //rect.right = template.cx + template.x; - //rect.bottom = template.cy + template.y; - - if (template.style & DS_MODALFRAME) - template.exStyle |= WS_EX_DLGMODALFRAME; - AdjustWindowRectEx( &rect, template.style, - hMenu ? TRUE : FALSE , template.exStyle ); - rect.right -= rect.left; - rect.bottom -= rect.top; - - - if ((INT)template.x == CW_USEDEFAULT) - { - rect.left = rect.top = CW_USEDEFAULT; - } - else - { - if (template.style & DS_CENTER) - { - rect.left = (SYSMETRICS_CXSCREEN - rect.right) / 2; - rect.top = (SYSMETRICS_CYSCREEN - rect.bottom) / 3; - } - else - { - rect.left += template.x * xUnit / 4; - rect.top += template.y * yUnit / 8; - } - if ( !(template.style & WS_CHILD) ) - { - INT dX, dY; - - if( !(template.style & DS_ABSALIGN) ) - ClientToScreen( owner, (POINT *)&rect ); - - /* try to fit it into the desktop */ - - if( (dX = rect.left + rect.right + SYSMETRICS_CXDLGFRAME - SYSMETRICS_CXSCREEN) > 0 ) - rect.left -= dX; - if( (dY = rect.top + rect.bottom + SYSMETRICS_CYDLGFRAME - SYSMETRICS_CYSCREEN) > 0 ) - rect.top -= dY; - if( rect.left < 0 ) rect.left = 0; - if( rect.top < 0 ) rect.top = 0; - } - } - - -// template.style & ~WS_VISIBLE - -//template.style |= WS_VISIBLE; -//template.style |= WS_THICKFRAME; -//template.style |= WS_SYSMENU; - hwnd = CreateWindowExW(template.exStyle, (LPCWSTR)template.className, - (LPCWSTR)template.caption, - template.style & ~WS_VISIBLE , - rect.left, rect.top, rect.right, rect.bottom , - owner, hMenu, hInst, NULL ); - - - - if (!hwnd) - { - if (hFont) DeleteObject( hFont ); - if (hMenu) DestroyMenu( hMenu ); - return 0; - } - wndPtr = WIN_FindWndPtr( hwnd ); - wndPtr->flags |= WIN_ISDIALOG; - wndPtr->helpContext = template.helpId; - wndPtr->winproc = dlgProc; - - /* Initialise dialog extra data */ - - dlgInfo = (DIALOGINFO *)wndPtr->wExtra; - dlgInfo->dlgProc = dlgProc; - //dlgInfo->hUserFont = hFont; - dlgInfo->hUserFont = NULL; - - dlgInfo->hMenu = hMenu; - dlgInfo->xBaseUnit = xUnit; - dlgInfo->yBaseUnit = yUnit; - dlgInfo->msgResult = 0; - dlgInfo->idResult = 0; - dlgInfo->flags = 0; - dlgInfo->hDialogHeap = 0; - - if (dlgInfo->hUserFont) - MSG_SendMessage( wndPtr, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0L); - - /* Create controls */ - - - - if (!DIALOG_CreateControls( hwnd, dlgInfo, dlgItemTemplate, template.nbItems, hInst , template.dialogEx)) - { - DestroyWindow( hwnd ); - if (hFont) DeleteObject( hFont ); - if (hMenu) DestroyMenu( hMenu ); - return 0; - } - - - /* Send initialisation messages and set focus */ - - dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE ); - - if (MSG_SendMessage( wndPtr, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param)) - SetFocus( dlgInfo->hwndFocus ); - - - - if (template.style & WS_VISIBLE && !(wndPtr->dwStyle & WS_VISIBLE)) - { - ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */ - UpdateWindow( hwnd ); - } - - return hwnd; - -} - - - - - - -/*********************************************************************** - * DIALOG_IsAccelerator - */ -WINBOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM vKey ) -{ - HWND hwndControl = hwnd; - HWND hwndNext; - WND *wndPtr; - WINBOOL RetVal = FALSE; - INT dlgCode; - - if (vKey == VK_SPACE) - { - dlgCode = SendMessage( hwndControl, WM_GETDLGCODE, 0, 0 ); - if (dlgCode & DLGC_BUTTON) - { - SendMessage( hwndControl, WM_LBUTTONDOWN, 0, 0); - SendMessage( hwndControl, WM_LBUTTONUP, 0, 0); - RetVal = TRUE; - } - } - else - { - do - { - wndPtr = WIN_FindWndPtr( hwndControl ); - if (wndPtr != NULL && wndPtr->text != NULL && - (wndPtr->dwStyle & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) - { - dlgCode = SendMessage( hwndControl, WM_GETDLGCODE, 0, 0 ); - if (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) - { - /* find the accelerator key */ - LPSTR p = wndPtr->text - 2; - do - { - p = strchr( p + 2, '&' ); - } - while (p != NULL && p[1] == '&'); - - /* and check if it's the one we're looking for */ - if (p != NULL && toupper( p[1] ) == toupper( vKey ) ) - { - if ((dlgCode & DLGC_STATIC) || - (wndPtr->dwStyle & 0x0f) == BS_GROUPBOX ) - { - /* set focus to the control */ - SendMessage( hwndDlg, WM_NEXTDLGCTL, - hwndControl, 1); - /* and bump it on to next */ - SendMessage( hwndDlg, WM_NEXTDLGCTL, 0, 0); - } - else if (dlgCode & - (DLGC_DEFPUSHBUTTON | DLGC_UNDEFPUSHBUTTON)) - { - /* send command message as from the control */ - SendMessage( hwndDlg, WM_COMMAND, - MAKEWPARAM( LOWORD(wndPtr->wIDmenu), - BN_CLICKED ), - (LPARAM)hwndControl ); - } - else - { - /* click the control */ - SendMessage( hwndControl, WM_LBUTTONDOWN, (WPARAM) 0, (LPARAM)0); - SendMessage( hwndControl, WM_LBUTTONUP, (WPARAM)0, (LPARAM)0); - } - RetVal = TRUE; - break; - } - } - } - hwndNext = GetWindow( hwndControl, GW_CHILD ); - if (!hwndNext) - { - hwndNext = GetWindow( hwndControl, GW_HWNDNEXT ); - } - while (!hwndNext) - { - hwndControl = GetParent( hwndControl ); - if (hwndControl == hwndDlg) - { - hwndNext = GetWindow( hwndDlg, GW_CHILD ); - } - else - { - hwndNext = GetWindow( hwndControl, GW_HWNDNEXT ); - } - } - hwndControl = hwndNext; - } - while (hwndControl != hwnd); - } - return RetVal; -} - - -/*********************************************************************** - * DIALOG_IsDialogMessage - */ -WINBOOL DIALOG_IsDialogMessage( HWND hwnd, HWND hwndDlg, - UINT message, WPARAM wParam, - LPARAM lParam, WINBOOL *translate, - WINBOOL *dispatch, INT dlgCode ) -{ - *translate = *dispatch = FALSE; - - if (message == WM_PAINT) - { - /* Apparently, we have to handle this one as well */ - *dispatch = TRUE; - return TRUE; - } - - /* Only the key messages get special processing */ - if ((message != WM_KEYDOWN) && - (message != WM_SYSCHAR) && - (message != WM_CHAR)) - return FALSE; - - if (dlgCode & DLGC_WANTMESSAGE) - { - *translate = *dispatch = TRUE; - return TRUE; - } - - switch(message) - { - case WM_KEYDOWN: - switch(wParam) - { - case VK_TAB: - if (!(dlgCode & DLGC_WANTTAB)) - { - SendMessageA( hwndDlg, WM_NEXTDLGCTL, - (GetKeyState(VK_SHIFT) & 0x8000), 0 ); - return TRUE; - } - break; - - case VK_RIGHT: - case VK_DOWN: - case VK_LEFT: - case VK_UP: - if (!(dlgCode & DLGC_WANTARROWS)) - { - WINBOOL fPrevious = (wParam == VK_LEFT || wParam == VK_UP); - HWND hwndNext = - GetNextDlgGroupItem (hwndDlg, GetFocus(), fPrevious ); - SendMessageA( hwndDlg, WM_NEXTDLGCTL, hwndNext, 1 ); - return TRUE; - } - break; - - case VK_ESCAPE: - SendMessageA( hwndDlg, WM_COMMAND, IDCANCEL, - (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) ); - return TRUE; - - case VK_RETURN: - { - DWORD dw = SendMessage( hwndDlg, DM_GETDEFID, 0, 0 ); - if (HIWORD(dw) == DC_HASDEFID) - { - SendMessageA( hwndDlg, WM_COMMAND, - MAKEWPARAM( LOWORD(dw), BN_CLICKED ), - (LPARAM)GetDlgItem(hwndDlg, LOWORD(dw))); - } - else - { - SendMessageA( hwndDlg, WM_COMMAND, IDOK, - (LPARAM)GetDlgItem( hwndDlg, IDOK ) ); - - } - } - return TRUE; - } - *translate = TRUE; - break; /* case WM_KEYDOWN */ - - case WM_CHAR: - if (dlgCode & DLGC_WANTCHARS) break; - /* drop through */ - - case WM_SYSCHAR: - if (DIALOG_IsAccelerator( hwnd, hwndDlg, wParam )) - { - /* don't translate or dispatch */ - return TRUE; - } - break; - } - - /* If we get here, the message has not been treated specially */ - /* and can be sent to its destination window. */ - *dispatch = TRUE; - return TRUE; -} - - - diff --git a/reactos/lib/user32/internal/event.c b/reactos/lib/user32/internal/event.c deleted file mode 100644 index 427d7884c30..00000000000 --- a/reactos/lib/user32/internal/event.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * X events handling functions - * - * Copyright 1993 Alexandre Julliard - * - */ - -#include - -/*********************************************************************** - * EVENT_WaitNetEvent - * - * Wait for a network event, optionally sleeping until one arrives. - * Return TRUE if an event is pending, FALSE on timeout or error - * (for instance lost connection with the server). - */ -WINBOOL EVENT_WaitNetEvent(WINBOOL sleep, WINBOOL peek) -{ - return TRUE; -} - - - -/********************************************************************** - * EVENT_CheckFocus - */ -WINBOOL EVENT_CheckFocus(void) -{ - return TRUE; -} - - - -/********************************************************************** - * X11DRV_EVENT_Pending - */ -WINBOOL EVENT_Pending() -{ - return FALSE; -} - -UINT EVENT_GetCaptureInfo(void) -{ -} - diff --git a/reactos/lib/user32/internal/heapdup.c b/reactos/lib/user32/internal/heapdup.c deleted file mode 100644 index f1414b09e86..00000000000 --- a/reactos/lib/user32/internal/heapdup.c +++ /dev/null @@ -1,119 +0,0 @@ -#include -#include - -LPVOID HEAP_strdupAtoW(HANDLE hHeap,DWORD dwFlags, LPCSTR lpszAsciiString ) -{ - int i; - INT len = lstrlenA(lpszAsciiString); - LPWSTR lpszUnicodeString = HeapAlloc(hHeap, dwFlags, (len + 1)*2 ); - for(i=0;i -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -//#include - -typedef struct tagMDINEXTMENU -{ - HMENU hmenuIn; - HMENU hmenuNext; - HWND hwndNext; -} MDINEXTMENU, *PMDINEXTMENU, * LPMDINEXTMENU; - -//FIXME should be defined in defines.h -#define MFT_RIGHTORDER 0x00002000L - -/* Wine extension, I think. */ -#define OBM_RADIOCHECK 32727 - - /* Dimension of the menu bitmaps */ -static WORD check_bitmap_width = 0, check_bitmap_height = 0; -static WORD arrow_bitmap_width = 0, arrow_bitmap_height = 0; - -#define MAX(x,y) x > y ? x : y - -DWORD STDCALL GetTextExtent(HDC,LPCWSTR,INT); - -static HBITMAP hStdRadioCheck = 0; -static HBITMAP hStdCheck = 0; -static HBITMAP hStdMnArrow = 0; -static HBRUSH hShadeBrush = 0; -HMENU MENU_DefSysPopup = 0; /* Default system menu popup */ - -/* Use global popup window because there's no way 2 menus can - * be tracked at the same time. */ - -WND* pTopPopupWnd = 0; -UINT uSubPWndLevel = 0; - - /* Flag set by EndMenu() to force an exit from menu tracking */ -WINBOOL fEndMenu = FALSE; - - - -/*********************************************************************** - * debug_print_menuitem - * - * Print a menuitem in readable form. - */ -#if 0 - -#define debug_print_menuitem(pre, mp, post) \ - if(!TRACE_ON(menu)) ; else do_debug_print_menuitem(pre, mp, post) - -#define MENUOUT(text) \ - sprintf(menu, "%s%s", (count++ ? "," : ""), (text)) - - - -#define MENUFLAG(bit,text) \ - do { \ - if (flags & (bit)) { flags &= ~(bit); MENUOUT ((text)); } \ - } while (0) - -static void do_debug_print_menuitem(const char *prefix, MENUITEM * mp, - const char *postfix) -{ - //dbg_decl_str(menu, 256); - - char menu[256]; - if (mp) { - UINT flags = mp->fType; - int typ = MENU_ITEM_TYPE(flags); - sprintf(menu, "{ ID=0x%x", mp->wID); - if (flags & MF_POPUP) - sprintf(menu, ", Sub=0x%x",(int) mp->hSubMenu); - if (flags) { - int count = 0; - sprintf(menu, ", Typ="); - if (typ == MFT_STRING) - /* Nothing */ ; - else if (typ == MFT_SEPARATOR) - MENUOUT("sep"); - else if (typ == MFT_OWNERDRAW) - MENUOUT("own"); - else if (typ == MFT_BITMAP) - MENUOUT("bit"); - else - MENUOUT("???"); - flags -= typ; - - MENUFLAG(MF_POPUP, "pop"); - MENUFLAG(MFT_MENUBARBREAK, "barbrk"); - MENUFLAG(MFT_MENUBREAK, "brk"); - MENUFLAG(MFT_RADIOCHECK, "radio"); - MENUFLAG(MFT_RIGHTORDER, "rorder"); - MENUFLAG(MF_SYSMENU, "sys"); - MENUFLAG(MFT_RIGHTJUSTIFY, "right"); - - if (flags) - sprintf(menu, "+0x%x", flags); - } - flags = mp->fState; - if (flags) { - int count = 0; - sprintf(menu, ", State="); - MENUFLAG(MFS_GRAYED, "grey"); - MENUFLAG(MFS_DISABLED, "dis"); - MENUFLAG(MFS_CHECKED, "check"); - MENUFLAG(MFS_HILITE, "hi"); - MENUFLAG(MF_USECHECKBITMAPS, "usebit"); - MENUFLAG(MF_MOUSESELECT, "mouse"); - if (flags) - sprintf(menu, "+0x%x", flags); - } - if (mp->hCheckBit) - sprintf(menu, ", Chk=0x%x",(int) mp->hCheckBit); - if (mp->hUnCheckBit) - sprintf(menu, ", Unc=0x%x",(int)mp->hUnCheckBit); - - if (typ == MFT_STRING) { - if (mp->text) - sprintf(menu, ", Text=\"%s\"", mp->text); - else - sprintf(menu, ", Text=Null"); - } else if (mp->text == NULL) - /* Nothing */ ; - else - sprintf(menu, ", Text=%p", mp->text); - sprintf(menu, " }"); - } else { - sprintf(menu, "NULL"); - } - - //DPRINT( "%s %s %s\n", prefix, dbg_str(menu), postfix); -} - -#undef MENUOUT -#undef MENUFLAG -#endif -/*********************************************************************** - * MENU_CopySysPopup - * - * Return the default system menu. - */ -HMENU MENU_CopySysPopup(void) -{ - HMENU hMenu = LoadMenuIndirectA(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU)); - - if( hMenu ) { - POPUPMENU* menu = (POPUPMENU *)(hMenu); - menu->wFlags |= MF_SYSMENU | MF_POPUP; - } - else { - hMenu = 0; -// DPRINT( "Unable to load default system menu\n" ); - } - -// DPRINT( "returning %x.\n", hMenu ); - - return hMenu; -} - - -/********************************************************************** - * MENU_GetSysMenu - * - * Create a copy of the system menu. System menu in Windows is - * a special menu-bar with the single entry - system menu popup. - * This popup is presented to the outside world as a "system menu". - * However, the real system menu handle is sometimes seen in the - * WM_MENUSELECT paramemters (and Word 6 likes it this way). - */ -HMENU MENU_GetSysMenu( HWND hWnd, HMENU hPopupMenu ) -{ - HMENU hMenu; - - if ((hMenu = CreateMenu())) - { - POPUPMENU *menu = (POPUPMENU*) (hMenu); - menu->wFlags = MF_SYSMENU; - menu->hWnd = hWnd; - - if (hPopupMenu == (HMENU)(-1)) - hPopupMenu = MENU_CopySysPopup(); - else if( !hPopupMenu ) hPopupMenu = MENU_DefSysPopup; - - if (hPopupMenu) - { - InsertMenuA( hMenu, -1, MF_SYSMENU | MF_POPUP | MF_BYPOSITION, (int)hPopupMenu, NULL ); - - menu->items[0].fType = MF_SYSMENU | MF_POPUP; - menu->items[0].fState = 0; - menu = (POPUPMENU*) (hPopupMenu); - menu->wFlags |= MF_SYSMENU; - -// DPRINT("GetSysMenu hMenu=%04x (%04x)\n", hMenu, hPopupMenu ); - return hMenu; - } - DestroyMenu( hMenu ); - } -// ERR(menu, "failed to load system menu!\n"); - return 0; -} - - -/*********************************************************************** - * MENU_Init - * - * Menus initialisation. - */ -WINBOOL MENU_Init() -{ - HBITMAP hBitmap; - static unsigned char shade_bits[] = { 0x55, 0, 0xAA, 0, - 0x55, 0, 0xAA, 0, - 0x55, 0, 0xAA, 0, - 0x55, 0, 0xAA, 0 }; - - /* Load menu bitmaps */ - hStdCheck = LoadBitmapA(0, MAKEINTRESOURCE(OBM_CHECK)); - hStdRadioCheck = LoadBitmapA(0, MAKEINTRESOURCE(OBM_RADIOCHECK)); - hStdMnArrow = LoadBitmapA(0, MAKEINTRESOURCE(OBM_MNARROW)); - - if (hStdCheck) - { - BITMAP bm; - GetObjectA( hStdCheck, sizeof(bm), &bm ); - check_bitmap_width = bm.bmWidth; - check_bitmap_height = bm.bmHeight; - } else - return FALSE; - - /* Assume that radio checks have the same size as regular check. */ - if (!hStdRadioCheck) - return FALSE; - - if (hStdMnArrow) - { - BITMAP bm; - GetObjectA( hStdMnArrow, sizeof(bm), &bm ); - arrow_bitmap_width = bm.bmWidth; - arrow_bitmap_height = bm.bmHeight; - } else - return FALSE; - - if ((hBitmap = CreateBitmap( 8, 8, 1, 1, shade_bits))) - { - if((hShadeBrush = CreatePatternBrush( hBitmap ))) - { - DeleteObject( hBitmap ); - if ((MENU_DefSysPopup = MENU_CopySysPopup())) - return TRUE; - } - } - - return FALSE; -} - -/*********************************************************************** - * MENU_InitSysMenuPopup - * - * Grey the appropriate items in System menu. - */ - void MENU_InitSysMenuPopup( HMENU hmenu, DWORD style, DWORD clsStyle ) -{ - WINBOOL gray; - - gray = !(style & WS_THICKFRAME) || (style & (WS_MAXIMIZE | WS_MINIMIZE)); - EnableMenuItem( hmenu, SC_SIZE, (gray ? MF_GRAYED : MF_ENABLED) ); - gray = ((style & WS_MAXIMIZE) != 0); - EnableMenuItem( hmenu, SC_MOVE, (gray ? MF_GRAYED : MF_ENABLED) ); - gray = !(style & WS_MINIMIZEBOX) || (style & WS_MINIMIZE); - EnableMenuItem( hmenu, SC_MINIMIZE, (gray ? MF_GRAYED : MF_ENABLED) ); - gray = !(style & WS_MAXIMIZEBOX) || (style & WS_MAXIMIZE); - EnableMenuItem( hmenu, SC_MAXIMIZE, (gray ? MF_GRAYED : MF_ENABLED) ); - gray = !(style & (WS_MAXIMIZE | WS_MINIMIZE)); - EnableMenuItem( hmenu, SC_RESTORE, (gray ? MF_GRAYED : MF_ENABLED) ); - gray = (clsStyle & CS_NOCLOSE) != 0; - EnableMenuItem( hmenu, SC_CLOSE, (gray ? MF_GRAYED : MF_ENABLED) ); -} - - -/****************************************************************************** - * - * UINT MENU_GetStartOfNextColumn( - * HMENU hMenu ) - * - *****************************************************************************/ - - UINT MENU_GetStartOfNextColumn( - HMENU hMenu ) -{ - POPUPMENU *menu = (POPUPMENU *)(hMenu); - UINT i = menu->FocusedItem + 1; - - if(!menu) - return NO_SELECTED_ITEM; - - if( i == NO_SELECTED_ITEM ) - return i; - - for( ; i < menu->nItems; ++i ) { - if (menu->items[i].fType & MF_MENUBARBREAK) - return i; - } - - return NO_SELECTED_ITEM; -} - - -/****************************************************************************** - * - * UINT MENU_GetStartOfPrevColumn( - * HMENU hMenu ) - * - *****************************************************************************/ - - UINT MENU_GetStartOfPrevColumn( - HMENU hMenu ) -{ - POPUPMENU const *menu = (POPUPMENU *)(hMenu); - UINT i; - - if( !menu ) - return NO_SELECTED_ITEM; - - if( menu->FocusedItem == 0 || menu->FocusedItem == NO_SELECTED_ITEM ) - return NO_SELECTED_ITEM; - - /* Find the start of the column */ - - for(i = menu->FocusedItem; i != 0 && - !(menu->items[i].fType & MF_MENUBARBREAK); - --i); /* empty */ - - if(i == 0) - return NO_SELECTED_ITEM; - - for(--i; i != 0; --i) { - if (menu->items[i].fType & MF_MENUBARBREAK) - break; - } - -// DPRINT( "ret %d.\n", i ); - - return i; -} - - - -/*********************************************************************** - * MENU_GetMenuBarHeight - * - * Compute the size of the menu bar height. Used by NC_HandleNCCalcSize(). - */ -UINT MENU_GetMenuBarHeight( HWND hwnd, UINT menubarWidth, - INT orgX, INT orgY ) -{ - HDC hdc; - RECT rectBar; - WND *wndPtr; - LPPOPUPMENU lppop; - - - - if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0; - if (!(lppop = (LPPOPUPMENU)((HMENU)wndPtr->wIDmenu))) - return 0; - hdc = GetDCEx( hwnd, 0, DCX_CACHE | DCX_WINDOW ); - SetRect(&rectBar, orgX, orgY, orgX+menubarWidth, orgY+SYSMETRICS_CYMENU); - MENU_MenuBarCalcSize( hdc, &rectBar, lppop, hwnd ); - ReleaseDC( hwnd, hdc ); - return lppop->Height; -} - - - -/*********************************************************************** - * MENU_FindItem - * - * Find a menu item. Return a pointer on the item, and modifies *hmenu - * in case the item was in a sub-menu. - */ - MENUITEM *MENU_FindItem( HMENU *hmenu, UINT *nPos, UINT wFlags ) -{ - POPUPMENU *menu; - UINT i; - - if (!(menu = (POPUPMENU *)(*hmenu))) return NULL; - if (wFlags & MF_BYPOSITION) - { - if (*nPos >= menu->nItems) return NULL; - return &menu->items[*nPos]; - } - else - { - MENUITEM *item = menu->items; - for (i = 0; i < menu->nItems; i++, item++) - { - if (item->wID == *nPos) - { - *nPos = i; - return item; - } - else if (item->fType & MF_POPUP) - { - HMENU hsubmenu = item->hSubMenu; - MENUITEM *subitem = MENU_FindItem( &hsubmenu, nPos, wFlags ); - if (subitem) - { - *hmenu = hsubmenu; - return subitem; - } - } - } - } - return NULL; -} - -/*********************************************************************** - * MENU_FreeItemData - */ -void MENU_FreeItemData( MENUITEM* item ) -{ - /* delete text */ - if (IS_STRING_ITEM(item->fType) && item->text) - HeapFree( GetProcessHeap(), 0, item->text ); -} - -/*********************************************************************** - * MENU_FindItemByCoords - * - * Find the item at the specified coordinates (screen coords). Does - * not work for child windows and therefore should not be called for - * an arbitrary system menu. - */ -MENUITEM *MENU_FindItemByCoords( POPUPMENU *menu, - POINT pt, UINT *pos ) -{ - MENUITEM *item; - WND *wndPtr; - UINT i; - - if (!(wndPtr = WIN_FindWndPtr( menu->hWnd ))) return NULL; - pt.x -= wndPtr->rectWindow.left; - pt.y -= wndPtr->rectWindow.top; - item = menu->items; - for (i = 0; i < menu->nItems; i++, item++) - { - if ((pt.x >= item->rect.left) && (pt.x < item->rect.right) && - (pt.y >= item->rect.top) && (pt.y < item->rect.bottom)) - { - if (pos) *pos = i; - return item; - } - } - return NULL; -} - - -/*********************************************************************** - * MENU_FindItemByKey - * - * Find the menu item selected by a key press. - * Return item id, -1 if none, -2 if we should close the menu. - */ -UINT MENU_FindItemByKey( HWND hwndOwner, HMENU hmenu, - UINT key, WINBOOL forceMenuChar ) -{ -// DPRINT("\tlooking for '%c' in [%04x]\n", (char)key, (UINT)hmenu ); - - if (!IsMenu( hmenu )) - { - WND* w = WIN_FindWndPtr(hwndOwner); - hmenu = GetSubMenu(w->hSysMenu, 0); - } - - if (hmenu) - { - POPUPMENU *menu = (POPUPMENU *) ( hmenu ); - MENUITEM *item = menu->items; - LONG menuchar; - - if( !forceMenuChar ) - { - UINT i; - - key = toupper(key); - for (i = 0; i < menu->nItems; i++, item++) - { - if (item->text && (IS_STRING_ITEM(item->fType))) - { - WCHAR *p = item->text - 2; - do - { - p = wcschr (p + 2, '&'); - } - while (p != NULL && p [1] == '&'); - if (p && (towupper(p[1]) == key)) return i; - } - } - } - menuchar = SendMessageW( hwndOwner, WM_MENUCHAR, (WPARAM)MAKEWPARAM( key, menu->wFlags ),(LPARAM) hmenu ); - if (HIWORD(menuchar) == 2) return LOWORD(menuchar); - if (HIWORD(menuchar) == 1) return (UINT)(-2); - } - return (UINT)(-1); -} - - -/*********************************************************************** - * MENU_CalcItemSize - * - * Calculate the size of the menu item and store it in lpitem->rect. - */ -void MENU_CalcItemSize( HDC hdc, MENUITEM *lpitem, HWND hwndOwner, - INT orgX, INT orgY, WINBOOL menuBar ) -{ - SIZE szSize; - WCHAR *p; - -// DPRINT( "HDC 0x%x at (%d,%d)\n", -// hdc, orgX, orgY); -// debug_print_menuitem("MENU_CalcItemSize: menuitem:", lpitem, -// (menuBar ? " (MenuBar)" : "")); - - SetRect( &lpitem->rect, orgX, orgY, orgX, orgY ); - - if (lpitem->fType & MF_OWNERDRAW) - { - MEASUREITEMSTRUCT mis; - mis.CtlType = ODT_MENU; - mis.itemID = lpitem->wID; - mis.itemData = (DWORD)lpitem->text; - mis.itemHeight = 16; - mis.itemWidth = 30; - SendMessageW( hwndOwner, WM_MEASUREITEM, 0, (LPARAM)&mis ); - lpitem->rect.bottom += mis.itemHeight; - lpitem->rect.right += mis.itemWidth; -// DPRINT( "%08x %dx%d\n", -// lpitem->wID, mis.itemWidth, mis.itemHeight); - return; - } - - if (lpitem->fType & MF_SEPARATOR) - { - lpitem->rect.bottom += SEPARATOR_HEIGHT; - return; - } - - if (!menuBar) - { - lpitem->rect.right += 2 * check_bitmap_width; - if (lpitem->fType & MF_POPUP) - lpitem->rect.right += arrow_bitmap_width; - } - - if (lpitem->fType & MF_BITMAP) - { - BITMAP bm; - if (GetObjectA( (HBITMAP)lpitem->text, sizeof(bm), &bm )) - { - lpitem->rect.right += bm.bmWidth; - lpitem->rect.bottom += bm.bmHeight; - } - return; - } - - /* If we get here, then it must be a text item */ - - if (IS_STRING_ITEM( lpitem->fType )) - { - GetTextExtentPointW( hdc, lpitem->text, wcslen(lpitem->text), &szSize ); - lpitem->rect.right += LOWORD(szSize.cx); - if (TWEAK_WineLook == WIN31_LOOK) - lpitem->rect.bottom += MAX( HIWORD(szSize.cy), SYSMETRICS_CYMENU ); - else - lpitem->rect.bottom += MAX(HIWORD(szSize.cy), sysMetrics[SM_CYMENU]- 1); - lpitem->xTab = 0; - - if (menuBar) lpitem->rect.right += MENU_BAR_ITEMS_SPACE; - else if ((p = wcschr( lpitem->text, '\t' )) != NULL) - { - /* Item contains a tab (only meaningful in popup menus) */ - lpitem->xTab = check_bitmap_width + MENU_TAB_SPACE; - GetTextExtentPoint32W( hdc, lpitem->text,(int)(p - lpitem->text) , &szSize); - lpitem->xTab += szSize.cx; - lpitem->rect.right += MENU_TAB_SPACE; - } - else - { - if (wcschr( lpitem->text, '\b' )) - lpitem->rect.right += MENU_TAB_SPACE; - lpitem->xTab = lpitem->rect.right - check_bitmap_width - - arrow_bitmap_width; - } - } -} - - -/*********************************************************************** - * MENU_PopupMenuCalcSize - * - * Calculate the size of a popup menu. - */ -void MENU_PopupMenuCalcSize( LPPOPUPMENU lppop, HWND hwndOwner ) -{ - MENUITEM *lpitem; - HDC hdc; - int start, i; - int orgX, orgY, maxX, maxTab, maxTabWidth; - - lppop->Width = lppop->Height = 0; - if (lppop->nItems == 0) return; - hdc = GetDC( 0 ); - start = 0; - maxX = SYSMETRICS_CXBORDER; - while (start < lppop->nItems) - { - lpitem = &lppop->items[start]; - orgX = maxX; - orgY = SYSMETRICS_CYBORDER; - - maxTab = maxTabWidth = 0; - - /* Parse items until column break or end of menu */ - for (i = start; i < lppop->nItems; i++, lpitem++) - { - if ((i != start) && - (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break; - - - if (TWEAK_WineLook > WIN31_LOOK) - ++orgY; - - MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, FALSE ); - if (lpitem->fType & MF_MENUBARBREAK) orgX++; - maxX = MAX( maxX, lpitem->rect.right ); - orgY = lpitem->rect.bottom; - if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab) - { - maxTab = MAX( maxTab, lpitem->xTab ); - maxTabWidth = MAX(maxTabWidth,lpitem->rect.right-lpitem->xTab); - } - } - - /* Finish the column (set all items to the largest width found) */ - maxX = MAX( maxX, maxTab + maxTabWidth ); - for (lpitem = &lppop->items[start]; start < i; start++, lpitem++) - { - lpitem->rect.right = maxX; - if (IS_STRING_ITEM(lpitem->fType) && lpitem->xTab) - lpitem->xTab = maxTab; - } - lppop->Height = MAX( lppop->Height, orgY ); - } - - - if(TWEAK_WineLook > WIN31_LOOK) - lppop->Height++; - - lppop->Width = maxX; - ReleaseDC( 0, hdc ); -} - - -/*********************************************************************** - * MENU_MenuBarCalcSize - * - * FIXME: Word 6 implements its own MDI and its own 'close window' bitmap - * height is off by 1 pixel which causes lengthy window relocations when - * active document window is maximized/restored. - * - * Calculate the size of the menu bar. - */ -void MENU_MenuBarCalcSize( HDC hdc, LPRECT lprect, - LPPOPUPMENU lppop, HWND hwndOwner ) -{ - MENUITEM *lpitem; - int start, i, orgX, orgY, maxY, helpPos; - - if ((lprect == NULL) || (lppop == NULL)) return; - if (lppop->nItems == 0) return; - DPRINT("left=%d top=%d right=%d bottom=%d\n", - lprect->left, lprect->top, lprect->right, lprect->bottom); - lppop->Width = lprect->right - lprect->left; - lppop->Height = 0; - maxY = lprect->top; - start = 0; - helpPos = -1; - while (start < lppop->nItems) - { - lpitem = &lppop->items[start]; - orgX = lprect->left; - orgY = maxY; - - /* Parse items until line break or end of menu */ - for (i = start; i < lppop->nItems; i++, lpitem++) - { - if ((helpPos == -1) && (lpitem->fType & MF_HELP)) helpPos = i; - if ((i != start) && - (lpitem->fType & (MF_MENUBREAK | MF_MENUBARBREAK))) break; - - DPRINT( "calling MENU_CalcItemSize org=(%d, %d)\n", orgX, orgY ); -// debug_print_menuitem (" item: ", lpitem, ""); - MENU_CalcItemSize( hdc, lpitem, hwndOwner, orgX, orgY, TRUE ); - if (lpitem->rect.right > lprect->right) - { - if (i != start) break; - else lpitem->rect.right = lprect->right; - } - maxY = MAX( maxY, lpitem->rect.bottom ); - orgX = lpitem->rect.right; - } - - /* Finish the line (set all items to the largest height found) */ - while (start < i) lppop->items[start++].rect.bottom = maxY; - } - - lprect->bottom = maxY; - lppop->Height = lprect->bottom - lprect->top; - - /* Flush right all items between the MF_HELP and the last item */ - /* (if several lines, only move the last line) */ - if (helpPos != -1) - { - lpitem = &lppop->items[lppop->nItems-1]; - orgY = lpitem->rect.top; - orgX = lprect->right; - for (i = lppop->nItems - 1; i >= helpPos; i--, lpitem--) - { - if (lpitem->rect.top != orgY) break; /* Other line */ - if (lpitem->rect.right >= orgX) break; /* Too far right already */ - lpitem->rect.left += orgX - lpitem->rect.right; - lpitem->rect.right = orgX; - orgX = lpitem->rect.left; - } - } -} - -/*********************************************************************** - * MENU_DrawMenuItem - * - * Draw a single menu item. - */ - void MENU_DrawMenuItem( HWND hwnd, HDC hdc, MENUITEM *lpitem, - UINT height, WINBOOL menuBar, UINT odaction ) -{ - RECT rect; - - //debug_print_menuitem("MENU_DrawMenuItem: ", lpitem, ""); - - if (lpitem->fType & MF_SYSMENU) - { - if( !IsIconic(hwnd) ) { - if (TWEAK_WineLook > WIN31_LOOK) - NC_DrawSysButton95( hwnd, hdc, - lpitem->fState & - (MF_HILITE | MF_MOUSESELECT) ); - else - NC_DrawSysButton( hwnd, hdc, - lpitem->fState & - (MF_HILITE | MF_MOUSESELECT) ); - } - - return; - } - - if (lpitem->fType & MF_OWNERDRAW) - { - DRAWITEMSTRUCT dis; - - dis.CtlType = ODT_MENU; - dis.itemID = lpitem->wID; - dis.itemData = (DWORD)lpitem->text; - dis.itemState = 0; - if (lpitem->fState & MF_CHECKED) dis.itemState |= ODS_CHECKED; - if (lpitem->fState & MF_GRAYED) dis.itemState |= ODS_GRAYED; - if (lpitem->fState & MF_HILITE) dis.itemState |= ODS_SELECTED; - dis.itemAction = odaction; /* ODA_DRAWENTIRE | ODA_SELECT | ODA_FOCUS; */ - dis.hwndItem = hwnd; - dis.hDC = hdc; - dis.rcItem = lpitem->rect; - //DPRINT( "Ownerdraw: itemID=%d, itemState=%d, itemAction=%d, " - // "hwndItem=%04x, hdc=%04x, rcItem={%d,%d,%d,%d}\n",dis.itemID, - // dis.itemState, dis.itemAction, dis.hwndItem, dis.hDC, - // dis.rcItem.left, dis.rcItem.top, dis.rcItem.right, - // dis.rcItem.bottom ); - SendMessageW( GetWindow(hwnd,GW_OWNER), WM_DRAWITEM, 0, (LPARAM)&dis ); - return; - } - - if (menuBar && (lpitem->fType & MF_SEPARATOR)) return; - rect = lpitem->rect; - - /* Draw the background */ - if (TWEAK_WineLook > WIN31_LOOK) { - rect.left += 2; - rect.right -= 2; - - /* - if(menuBar) { - --rect.left; - ++rect.bottom; - --rect.top; - } - InflateRect( &rect, -1, -1 ); - */ - } - - if (lpitem->fState & MF_HILITE) - FillRect( hdc, &rect, GetSysColorBrush(COLOR_HIGHLIGHT) ); - else - FillRect( hdc, &rect, GetSysColorBrush(COLOR_MENU) ); - - SetBkMode( hdc, TRANSPARENT ); - - /* Draw the separator bar (if any) */ - - if (!menuBar && (lpitem->fType & MF_MENUBARBREAK)) - { - /* vertical separator */ - if (TWEAK_WineLook > WIN31_LOOK) { - RECT rc = rect; - rc.top = 3; - rc.bottom = height - 3; - DrawEdge (hdc, &rc, EDGE_ETCHED, BF_LEFT); - } - else { - SelectObject( hdc,(HGDIOBJ) GetSysColorPen(COLOR_WINDOWFRAME) ); - MoveToEx( hdc, rect.left, 0,NULL ); - LineTo( hdc, rect.left, height ); - } - } - if (lpitem->fType & MF_SEPARATOR) - { - /* horizontal separator */ - if (TWEAK_WineLook > WIN31_LOOK) { - RECT rc = rect; - rc.left++; - rc.right--; - rc.top += SEPARATOR_HEIGHT / 2; - DrawEdge (hdc, &rc, EDGE_ETCHED, BF_TOP); - } - else { - SelectObject( hdc,(HGDIOBJ) GetSysColorPen(COLOR_WINDOWFRAME) ); - MoveToEx( hdc, rect.left, rect.top + SEPARATOR_HEIGHT/2 ,NULL); - LineTo( hdc, rect.right, rect.top + SEPARATOR_HEIGHT/2 ); - } - - return; - } - - /* Setup colors */ - - if (lpitem->fState & MF_HILITE) - { - if (lpitem->fState & MF_GRAYED) - SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) ); - else - SetTextColor( hdc, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); - SetBkColor( hdc, GetSysColor( COLOR_HIGHLIGHT ) ); - } - else - { - if (lpitem->fState & MF_GRAYED) - SetTextColor( hdc, GetSysColor( COLOR_GRAYTEXT ) ); - else - SetTextColor( hdc, GetSysColor( COLOR_MENUTEXT ) ); - SetBkColor( hdc, GetSysColor( COLOR_MENU ) ); - } - - if (!menuBar) - { - INT y = rect.top + rect.bottom; - - /* Draw the check mark - * - * FIXME: - * Custom checkmark bitmaps are monochrome but not always 1bpp. - */ - - if (lpitem->fState & MF_CHECKED) - { - HBITMAP bm = - lpitem->hCheckBit ? lpitem->hCheckBit : - ((lpitem->fType & MFT_RADIOCHECK) - ? hStdRadioCheck : hStdCheck); - HDC hdcMem = CreateCompatibleDC( hdc ); - - SelectObject( hdcMem, bm ); - BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2, - check_bitmap_width, check_bitmap_height, - hdcMem, 0, 0, SRCCOPY ); - DeleteDC( hdcMem ); - } else if (lpitem->hUnCheckBit) { - HDC hdcMem = CreateCompatibleDC( hdc ); - - SelectObject( hdcMem, lpitem->hUnCheckBit ); - BitBlt( hdc, rect.left, (y - check_bitmap_height) / 2, - check_bitmap_width, check_bitmap_height, - hdcMem, 0, 0, SRCCOPY ); - DeleteDC( hdcMem ); - } - - /* Draw the popup-menu arrow */ - - if (lpitem->fType & MF_POPUP) - { - HDC hdcMem = CreateCompatibleDC( hdc ); - - SelectObject( hdcMem, hStdMnArrow ); - BitBlt( hdc, rect.right - arrow_bitmap_width - 1, - (y - arrow_bitmap_height) / 2, - arrow_bitmap_width, arrow_bitmap_height, - hdcMem, 0, 0, SRCCOPY ); - DeleteDC( hdcMem ); - } - - rect.left += check_bitmap_width; - rect.right -= arrow_bitmap_width; - } - - /* Draw the item text or bitmap */ - - if (lpitem->fType & MF_BITMAP) - { - HDC hdcMem = CreateCompatibleDC( hdc ); - - SelectObject( hdcMem, (HBITMAP)lpitem->text ); - BitBlt( hdc, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, hdcMem, 0, 0, SRCCOPY ); - DeleteDC( hdcMem ); - return; - } - /* No bitmap - process text if present */ - else if (IS_STRING_ITEM(lpitem->fType)) - { - register int i; - - if (menuBar) - { - rect.left += MENU_BAR_ITEMS_SPACE / 2; - rect.right -= MENU_BAR_ITEMS_SPACE / 2; - i = wcslen( lpitem->text ); - } - else - { - for (i = 0; lpitem->text[i]; i++) - if ((lpitem->text[i] == '\t') || (lpitem->text[i] == '\b')) - break; - } - - if((TWEAK_WineLook == WIN31_LOOK) || !(lpitem->fState & MF_GRAYED)) { - DrawTextW( hdc, lpitem->text, i, &rect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE ); - } - - else { - if (!(lpitem->fState & MF_HILITE)) - { - ++rect.left; - ++rect.top; - ++rect.right; - ++rect.bottom; - SetTextColor(hdc, RGB(0xff, 0xff, 0xff)); - DrawTextW( hdc, lpitem->text, i, &rect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE ); - --rect.left; - --rect.top; - --rect.right; - --rect.bottom; - } - SetTextColor(hdc, RGB(0x80, 0x80, 0x80)); - DrawTextW( hdc, lpitem->text, i, &rect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE ); - } - - if (lpitem->text[i]) /* There's a tab or flush-right char */ - { - if (lpitem->text[i] == '\t') - { - rect.left = lpitem->xTab; - DrawTextW( hdc, lpitem->text + i + 1, -1, &rect, - DT_LEFT | DT_VCENTER | DT_SINGLELINE ); - } - else DrawTextW( hdc, lpitem->text + i + 1, -1, &rect, - DT_RIGHT | DT_VCENTER | DT_SINGLELINE ); - } - } -} - -/*********************************************************************** - * MENU_DrawPopupMenu - * - * Paint a popup menu. - */ -void MENU_DrawPopupMenu( HWND hwnd, HDC hdc, HMENU hmenu ) -{ - HBRUSH hPrevBrush = 0; - RECT rect; - - GetClientRect( hwnd, &rect ); - - - rect.bottom -= POPUP_YSHADE * SYSMETRICS_CYBORDER; - rect.right -= POPUP_XSHADE * SYSMETRICS_CXBORDER; - - - if((hPrevBrush = SelectObject( hdc, GetSysColorBrush(COLOR_MENU) ))) - { - HPEN hPrevPen; - - Rectangle( hdc, rect.left, rect.top, rect.right, rect.bottom ); - - hPrevPen = SelectObject( hdc, GetStockObject( NULL_PEN ) ); - if( hPrevPen ) - { - POPUPMENU *menu; - - INT ropPrev, i; - - - /* draw 3-d shade */ - if(TWEAK_WineLook == WIN31_LOOK) { - SelectObject( hdc, hShadeBrush ); - SetBkMode( hdc, TRANSPARENT ); - ropPrev = SetROP2( hdc, R2_MASKPEN ); - - i = rect.right; /* why SetBrushOrg() doesn't? */ - PatBlt( hdc, i & 0xfffffffe, - rect.top + POPUP_YSHADE*SYSMETRICS_CYBORDER, - i%2 + POPUP_XSHADE*SYSMETRICS_CXBORDER, - rect.bottom - rect.top, 0x00a000c9 ); - i = rect.bottom; - PatBlt( hdc, rect.left + POPUP_XSHADE*SYSMETRICS_CXBORDER, - i & 0xfffffffe,rect.right - rect.left, - i%2 + POPUP_YSHADE*SYSMETRICS_CYBORDER, 0x00a000c9 ); - SelectObject( hdc, hPrevPen ); - SelectObject( hdc, hPrevBrush ); - SetROP2( hdc, ropPrev ); - } - else - DrawEdge (hdc, &rect, EDGE_RAISED, BF_RECT); - - /* draw menu items */ - - menu = (POPUPMENU *) ( hmenu ); - if (menu && menu->nItems) - { - MENUITEM *item; - UINT u; - - for (u = menu->nItems, item = menu->items; u > 0; u--, item++) - MENU_DrawMenuItem( hwnd, hdc, item, menu->Height, FALSE, - ODA_DRAWENTIRE ); - - } - } else SelectObject( hdc, hPrevBrush ); - } -} - - -/*********************************************************************** - * MENU_DrawMenuBar - * - * Paint a menu bar. Returns the height of the menu bar. - */ -UINT MENU_DrawMenuBar( HDC hDC, LPRECT lprect, HWND hwnd, - WINBOOL suppress_draw) -{ - LPPOPUPMENU lppop; - UINT i; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - lppop = (LPPOPUPMENU) ( (HMENU)wndPtr->wIDmenu ); - if (lppop == NULL || lprect == NULL) return SYSMETRICS_CYMENU; -// DPRINT("(%04x, %p, %p); !\n", hDC, lprect, lppop); - if (lppop->Height == 0) MENU_MenuBarCalcSize(hDC, lprect, lppop, hwnd); - lprect->bottom = lprect->top + lppop->Height; - if (suppress_draw) return lppop->Height; - - FillRect(hDC, lprect, GetSysColorBrush(COLOR_MENU) ); - - if (TWEAK_WineLook == WIN31_LOOK) { - SelectObject( hDC,(HGDIOBJ)GetSysColorPen(COLOR_WINDOWFRAME) ); - MoveToEx( hDC, lprect->left, lprect->bottom,NULL ); - LineTo( hDC, lprect->right, lprect->bottom ); - } - else { - SelectObject( hDC,(HGDIOBJ) GetSysColorPen(COLOR_3DFACE)); - MoveToEx( hDC, lprect->left, lprect->bottom,NULL ); - LineTo( hDC, lprect->right, lprect->bottom ); - } - - if (lppop->nItems == 0) return SYSMETRICS_CYMENU; - for (i = 0; i < lppop->nItems; i++) - { - MENU_DrawMenuItem( hwnd, hDC, &lppop->items[i], lppop->Height, TRUE, - ODA_DRAWENTIRE ); - } - return lppop->Height; -} - - -/*********************************************************************** - * MENU_PatchResidentPopup - */ -WINBOOL MENU_PatchResidentPopup( HQUEUE checkQueue, WND* checkWnd ) -{ - - return FALSE; -} - - -/*********************************************************************** - * MENU_ShowPopup - * - * Display a popup menu. - */ - WINBOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id, - INT x, INT y, INT xanchor, INT yanchor ) -{ - POPUPMENU *menu; - WND *wndOwner = NULL; - - if (!(menu = (POPUPMENU *) ( hmenu ))) return FALSE; - if (menu->FocusedItem != NO_SELECTED_ITEM) - { - menu->items[menu->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT); - menu->FocusedItem = NO_SELECTED_ITEM; - } - - if( (wndOwner = WIN_FindWndPtr( hwndOwner )) ) - { - UINT width, height; - - MENU_PopupMenuCalcSize( menu, hwndOwner ); - - /* adjust popup menu pos so that it fits within the desktop */ - - width = menu->Width + SYSMETRICS_CXBORDER; - height = menu->Height + SYSMETRICS_CYBORDER; - - if( x + width > SYSMETRICS_CXSCREEN ) - { - if( xanchor ) - x -= width - xanchor; - if( x + width > SYSMETRICS_CXSCREEN) - x = SYSMETRICS_CXSCREEN - width; - } - if( x < 0 ) x = 0; - - if( y + height > SYSMETRICS_CYSCREEN ) - { - if( yanchor ) - y -= height + yanchor; - if( y + height > SYSMETRICS_CYSCREEN ) - y = SYSMETRICS_CYSCREEN - height; - } - if( y < 0 ) y = 0; - - width += POPUP_XSHADE * SYSMETRICS_CXBORDER; /* add space for shading */ - height += POPUP_YSHADE * SYSMETRICS_CYBORDER; - - /* NOTE: In Windows, top menu popup is not owned. */ - if (!pTopPopupWnd) /* create top level popup menu window */ - { -// assert( uSubPWndLevel == 0 ); - - pTopPopupWnd = WIN_FindWndPtr(CreateWindowA( POPUPMENU_CLASS_NAME, NULL, - WS_POPUP, x, y, width, height, - hwndOwner, 0, wndOwner->hInstance, - (LPVOID)hmenu )); - if (!pTopPopupWnd) return FALSE; - menu->hWnd = pTopPopupWnd->hwndSelf; - } - else - if( uSubPWndLevel ) - { - /* create a new window for the submenu */ - - menu->hWnd = CreateWindowA( POPUPMENU_CLASS_NAME, NULL, - WS_POPUP, x, y, width, height, - menu->hWnd, 0, wndOwner->hInstance, - (LPVOID)hmenu ); - if( !menu->hWnd ) return FALSE; - } - else /* top level popup menu window already exists */ - { - menu->hWnd = pTopPopupWnd->hwndSelf; - MENU_PatchResidentPopup( 0, wndOwner ); - SendMessageW( pTopPopupWnd->hwndSelf, MM_SETMENUHANDLE, (WPARAM)hmenu, 0L); - - /* adjust its size */ - - SetWindowPos( menu->hWnd, 0, x, y, width, height, - SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOREDRAW); - } - - uSubPWndLevel++; /* menu level counter */ - - /* Display the window */ - - SetWindowPos( menu->hWnd, HWND_TOP, 0, 0, 0, 0, - SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE ); - UpdateWindow( menu->hWnd ); - return TRUE; - } - return FALSE; -} - - -/*********************************************************************** - * MENU_SelectItem - */ - void MENU_SelectItem( HWND hwndOwner, HMENU hmenu, UINT wIndex, - WINBOOL sendMenuSelect ) -{ - LPPOPUPMENU lppop; - HDC hdc; - - lppop = (POPUPMENU *) ( hmenu ); - if (!lppop->nItems) return; - - if ((wIndex != NO_SELECTED_ITEM) && - (lppop->items[wIndex].fType & MF_SEPARATOR)) - wIndex = NO_SELECTED_ITEM; - - if (lppop->FocusedItem == wIndex) return; - if (lppop->wFlags & MF_POPUP) hdc = GetDC( lppop->hWnd ); - else hdc = GetDCEx( lppop->hWnd, 0, DCX_CACHE | DCX_WINDOW); - - /* Clear previous highlighted item */ - if (lppop->FocusedItem != NO_SELECTED_ITEM) - { - lppop->items[lppop->FocusedItem].fState &= ~(MF_HILITE|MF_MOUSESELECT); - MENU_DrawMenuItem(lppop->hWnd,hdc,&lppop->items[lppop->FocusedItem], - lppop->Height, !(lppop->wFlags & MF_POPUP), - ODA_SELECT ); - } - - /* Highlight new item (if any) */ - lppop->FocusedItem = wIndex; - if (lppop->FocusedItem != NO_SELECTED_ITEM) - { - lppop->items[lppop->FocusedItem].fState |= MF_HILITE; - MENU_DrawMenuItem( lppop->hWnd, hdc, &lppop->items[lppop->FocusedItem], - lppop->Height, !(lppop->wFlags & MF_POPUP), - ODA_SELECT ); - if (sendMenuSelect) - { - MENUITEM *ip = &lppop->items[lppop->FocusedItem]; - SendMessageW( hwndOwner, WM_MENUSELECT, ip->wID, - MAKELONG(ip->fType | (ip->fState | MF_MOUSESELECT), - hmenu) ); - } - } - else if (sendMenuSelect) { - SendMessageW( hwndOwner, WM_MENUSELECT, (WPARAM)hmenu, - (LPARAM)MAKELONG( lppop->wFlags | MF_MOUSESELECT, hmenu ) ); - } - ReleaseDC( lppop->hWnd, hdc ); -} - - -/*********************************************************************** - * MENU_MoveSelection - * - * Moves currently selected item according to the offset parameter. - * If there is no selection then it should select the last item if - * offset is ITEM_PREV or the first item if offset is ITEM_NEXT. - */ - void MENU_MoveSelection( HWND hwndOwner, HMENU hmenu, INT offset ) -{ - INT i; - POPUPMENU *menu; - - menu = (POPUPMENU *) ( hmenu ); - if (!menu->items) return; - - if ( menu->FocusedItem != NO_SELECTED_ITEM ) - { - if( menu->nItems == 1 ) return; else - for (i = menu->FocusedItem + offset ; i >= 0 && i < menu->nItems - ; i += offset) - if (!(menu->items[i].fType & MF_SEPARATOR)) - { - MENU_SelectItem( hwndOwner, hmenu, i, TRUE ); - return; - } - } - - for ( i = (offset > 0) ? 0 : menu->nItems - 1; - i >= 0 && i < menu->nItems ; i += offset) - if (!(menu->items[i].fType & MF_SEPARATOR)) - { - MENU_SelectItem( hwndOwner, hmenu, i, TRUE ); - return; - } -} - - -/********************************************************************** - * MENU_SetItemData - * - * Set an item flags, id and text ptr. Called by InsertMenu() and - * ModifyMenu(). - */ - WINBOOL MENU_SetItemData( MENUITEM *item, UINT flags, UINT id, - LPCWSTR str ) -{ - LPWSTR prevText = IS_STRING_ITEM(item->fType) ? item->text : NULL; - -// debug_print_menuitem("MENU_SetItemData from: ", item, ""); - - if (IS_STRING_ITEM(flags)) - { - if (!str || !*str) - { - flags |= MF_SEPARATOR; - item->text = NULL; - } - else - { - LPWSTR text; - /* Item beginning with a backspace is a help item */ - if (*str == '\b') - { - flags |= MF_HELP; - str++; - } - - if ( ! (text = HEAP_strdupW(GetProcessHeap,0, str ) )) - return FALSE; - item->text = text; - } - } - else if (flags & MF_BITMAP) item->text = (LPWSTR)(HBITMAP)LOWORD(str); - else item->text = NULL; - - if (flags & MF_OWNERDRAW) - item->dwItemData = (DWORD)str; - else - item->dwItemData = 0; - - if ((item->fType & MF_POPUP) && (flags & MF_POPUP) && (item->hSubMenu != id) ) - DestroyMenu( item->hSubMenu ); /* ModifyMenu() spec */ - - if (flags & MF_POPUP) - { - POPUPMENU *menu = (POPUPMENU *)((UINT)id); - if (IS_A_MENU(menu)) menu->wFlags |= MF_POPUP; - else - { - item->wID = 0; - item->hSubMenu = 0; - item->fType = 0; - item->fState = 0; - return FALSE; - } - } - - item->wID = id; - if (flags & MF_POPUP) - item->hSubMenu = id; - - if ((item->fType & MF_POPUP) && !(flags & MF_POPUP) ) - flags |= MF_POPUP; /* keep popup */ - - item->fType = flags & TYPE_MASK; - item->fState = (flags & STATE_MASK) & - ~(MF_HILITE | MF_MOUSESELECT | MF_BYPOSITION); - - - /* Don't call SetRectEmpty here! */ - - - if (prevText) HeapFree( GetProcessHeap(), 0, prevText ); - -// debug_print_menuitem("MENU_SetItemData to : ", item, ""); - return TRUE; -} - - -/********************************************************************** - * MENU_InsertItem - * - * Insert a new item into a menu. - */ - MENUITEM *MENU_InsertItem( HMENU hMenu, UINT pos, UINT flags ) -{ - MENUITEM *newItems; - POPUPMENU *menu; - - if (!(menu = (POPUPMENU *)(hMenu))) - { - DPRINT( "%04x not a menu handle\n",(UINT)hMenu ); - return NULL; - } - - /* Find where to insert new item */ - - if ((flags & MF_BYPOSITION) && - ((pos == (UINT)-1) || (pos == menu->nItems))) - { - /* Special case: append to menu */ - /* Some programs specify the menu length to do that */ - pos = menu->nItems; - } - else - { - if (!MENU_FindItem( &hMenu, &pos, flags )) - { - DPRINT( "item %x not found\n",pos ); - return NULL; - } - if (!(menu = (LPPOPUPMENU) (hMenu))) - { - DPRINT("%04x not a menu handle\n",(UINT)hMenu); - return NULL; - } - } - - /* Create new items array */ - - newItems = HeapAlloc( GetProcessHeap(), 0, sizeof(MENUITEM) * (menu->nItems+1) ); - if (!newItems) - { - DPRINT( "allocation failed\n" ); - return NULL; - } - if (menu->nItems > 0) - { - /* Copy the old array into the new */ - if (pos > 0) memcpy( newItems, menu->items, pos * sizeof(MENUITEM) ); - if (pos < menu->nItems) memcpy( &newItems[pos+1], &menu->items[pos], - (menu->nItems-pos)*sizeof(MENUITEM) ); - HeapFree( GetProcessHeap(), 0, menu->items ); - } - menu->items = newItems; - menu->nItems++; - HEAP_memset( &newItems[pos], 0, sizeof(*newItems) ); - return &newItems[pos]; -} - - -/********************************************************************** - * MENU_ParseResource - * - * Parse a standard menu resource and add items to the menu. - * Return a pointer to the end of the resource. - */ -LPCWSTR MENU_ParseResource( LPCWSTR res, HMENU hMenu) -{ - WORD flags, id = 0; - LPWSTR str; - - do - { - flags = GET_WORD(res); - res += sizeof(WORD); - if (!(flags & MF_POPUP)) - { - id = GET_WORD(res); - res += sizeof(WORD); - } - if (!IS_STRING_ITEM(flags)) { - // DPRINT( "not a string item %04x\n", flags ); - } - str = (LPWSTR)res; - res += (lstrlenW((LPCWSTR)str) + 1) * sizeof(WCHAR); - if (flags & MF_POPUP) - { - HMENU hSubMenu = CreatePopupMenu(); - if (!hSubMenu) return NULL; - if (!(res = MENU_ParseResource( res, hSubMenu))) - return NULL; - AppendMenuW( hMenu, flags, (UINT)hSubMenu, (LPCWSTR)str ); - } - else /* Not a popup */ - { - AppendMenuW( hMenu, flags, id, - *(LPCWSTR)str ? (LPCWSTR)str : NULL ); - } - } while (!(flags & MF_END)); - return res; -} - - -/********************************************************************** - * MENUEX_ParseResource - * - * Parse an extended menu resource and add items to the menu. - * Return a pointer to the end of the resource. - */ -LPCWSTR MENUEX_ParseResource( LPCWSTR res, HMENU hMenu) -{ - WORD resinfo; - do { - MENUITEMINFO mii; - - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STATE | MIIM_ID | MIIM_TYPE; - mii.fType = GET_DWORD(res); - res += sizeof(DWORD); - mii.fState = GET_DWORD(res); - res += sizeof(DWORD); - mii.wID = GET_DWORD(res); - res += sizeof(DWORD); - resinfo = GET_WORD(res); /* FIXME: for -bit apps this is a byte. */ - res += sizeof(WORD); - /* Align the text on a word boundary. */ - res += (~((int)res - 1)) & 1; - mii.dwTypeData = (LPWSTR) res; - res += (1 + lstrlenW((LPWSTR)mii.dwTypeData)) * sizeof(WCHAR); - /* Align the following fields on a dword boundary. */ - res += (~((int)res - 1)) & 3; - - /* FIXME: This is inefficient and cannot be optimised away by gcc. */ -/* - { - LPSTR newstr = HEAP_strdupWtoA(GetProcessHeap(), - 0, mii.dwTypeData); - DPRINT( "Menu item: [%08x,%08x,%04x,%04x,%s]\n", - mii.fType, mii.fState, mii.wID, resinfo, newstr); - HeapFree( GetProcessHeap(), 0, newstr ); - } -*/ - if (resinfo & 1) { /* Pop-up? */ - // DWORD helpid = GET_DWORD(res); /* FIXME: use this. */ - res += sizeof(DWORD); - mii.hSubMenu = CreatePopupMenu(); - if (!mii.hSubMenu) - return NULL; - if (!(res = MENUEX_ParseResource(res, mii.hSubMenu))) { - DestroyMenu(mii.hSubMenu); - return NULL; - } - mii.fMask |= MIIM_SUBMENU; - mii.fType |= MF_POPUP; - } - InsertMenuItemW(hMenu, -1, MF_BYPOSITION, &mii); - } while (!(resinfo & MF_END)); - return res; -} - - -/*********************************************************************** - * MENU_GetSubPopup - * - * Return the handle of the selected sub-popup menu (if any). - */ - HMENU MENU_GetSubPopup( HMENU hmenu ) -{ - POPUPMENU *menu; - MENUITEM *item; - - menu = (POPUPMENU *) ( hmenu ); - - if (menu->FocusedItem == NO_SELECTED_ITEM) return 0; - - item = &menu->items[menu->FocusedItem]; - if ((item->fType & MF_POPUP) && (item->fState & MF_MOUSESELECT)) - return item->hSubMenu; - return 0; -} - - -/*********************************************************************** - * MENU_HideSubPopups - * - * Hide the sub-popup menus of this menu. - */ - void MENU_HideSubPopups( HWND hwndOwner, HMENU hmenu, - WINBOOL sendMenuSelect ) -{ - POPUPMENU *menu = (POPUPMENU*) ( hmenu );; - - if (menu && uSubPWndLevel) - { - HMENU hsubmenu; - POPUPMENU *submenu; - MENUITEM *item; - - if (menu->FocusedItem != NO_SELECTED_ITEM) - { - item = &menu->items[menu->FocusedItem]; - if (!(item->fType & MF_POPUP) || - !(item->fState & MF_MOUSESELECT)) return; - item->fState &= ~MF_MOUSESELECT; - hsubmenu = item->hSubMenu; - } else return; - - submenu = (POPUPMENU *) ( hsubmenu ); - MENU_HideSubPopups( hwndOwner, hsubmenu, FALSE ); - MENU_SelectItem( hwndOwner, hsubmenu, NO_SELECTED_ITEM, sendMenuSelect ); - - if (submenu->hWnd == pTopPopupWnd->hwndSelf ) - { - ShowWindow( submenu->hWnd, SW_HIDE ); - uSubPWndLevel = 0; - } - else - { - DestroyWindow( submenu->hWnd ); - submenu->hWnd = 0; - } - } -} - - -/*********************************************************************** - * MENU_ShowSubPopup - * - * Display the sub-menu of the selected item of this menu. - * Return the handle of the submenu, or hmenu if no submenu to display. - */ - HMENU MENU_ShowSubPopup( HWND hwndOwner, HMENU hmenu, - WINBOOL selectFirst ) -{ - RECT rect; - POPUPMENU *menu; - MENUITEM *item; - WND *wndPtr; - HDC hdc; - - if (!(menu = (POPUPMENU *) ( hmenu ))) return hmenu; - - if (!(wndPtr = WIN_FindWndPtr( menu->hWnd )) || - (menu->FocusedItem == NO_SELECTED_ITEM)) return hmenu; - - item = &menu->items[menu->FocusedItem]; - if (!(item->fType & MF_POPUP) || - (item->fState & (MF_GRAYED | MF_DISABLED))) return hmenu; - - /* message must be send before using item, - because nearly everything may by changed by the application ! */ - - SendMessageW( hwndOwner, WM_INITMENUPOPUP, (WPARAM)item->hSubMenu, - MAKELONG( menu->FocusedItem, IS_SYSTEM_MENU(menu) )); - - item = &menu->items[menu->FocusedItem]; - rect = item->rect; - - /* correct item if modified as a reaction to WM_INITMENUPOPUP-message */ - if (!(item->fState & MF_HILITE)) - { - if (menu->wFlags & MF_POPUP) hdc = GetDC( menu->hWnd ); - else hdc = GetDCEx( menu->hWnd, 0, DCX_CACHE | DCX_WINDOW); - item->fState |= MF_HILITE; - MENU_DrawMenuItem( menu->hWnd, hdc, item, menu->Height, !(menu->wFlags & MF_POPUP), ODA_DRAWENTIRE ); - ReleaseDC( menu->hWnd, hdc ); - } - if (!item->rect.top && !item->rect.left && !item->rect.bottom && !item->rect.right) - item->rect = rect; - - item->fState |= MF_MOUSESELECT; - - if (IS_SYSTEM_MENU(menu)) - { - MENU_InitSysMenuPopup(item->hSubMenu, wndPtr->dwStyle, wndPtr->class->style); - - NC_GetSysPopupPos( wndPtr, &rect ); - rect.top = rect.bottom; - rect.right = SYSMETRICS_CXSIZE; - rect.bottom = SYSMETRICS_CYSIZE; - } - else - { - if (menu->wFlags & MF_POPUP) - { - rect.left = wndPtr->rectWindow.left + item->rect.right-arrow_bitmap_width; - rect.top = wndPtr->rectWindow.top + item->rect.top; - rect.right = item->rect.left - item->rect.right + 2*arrow_bitmap_width; - rect.bottom = item->rect.top - item->rect.bottom; - } - else - { - rect.left = wndPtr->rectWindow.left + item->rect.left; - rect.top = wndPtr->rectWindow.top + item->rect.bottom; - rect.right = item->rect.right - item->rect.left; - rect.bottom = item->rect.bottom - item->rect.top; - } - } - - MENU_ShowPopup( hwndOwner, item->hSubMenu, menu->FocusedItem, - rect.left, rect.top, rect.right, rect.bottom ); - if (selectFirst) - MENU_MoveSelection( hwndOwner, item->hSubMenu, ITEM_NEXT ); - return item->hSubMenu; -} - -/*********************************************************************** - * MENU_PtMenu - * - * Walks menu chain trying to find a menu pt maps to. - */ - HMENU MENU_PtMenu( HMENU hMenu, POINT pt ) -{ - POPUPMENU *menu = (POPUPMENU *) ( hMenu ); - register UINT ht = menu->FocusedItem; - - /* try subpopup first (if any) */ - ht = (ht != NO_SELECTED_ITEM && - (menu->items[ht].fType & MF_POPUP) && - (menu->items[ht].fState & MF_MOUSESELECT)) - ? (UINT) MENU_PtMenu(menu->items[ht].hSubMenu, pt) : 0; - - if( !ht ) /* check the current window (avoiding WM_HITTEST) */ - { - ht = (UINT)NC_HandleNCHitTest( menu->hWnd, pt ); - if( menu->wFlags & MF_POPUP ) - ht = (ht != (UINT)HTNOWHERE && - ht != (UINT)HTERROR) ? (UINT)hMenu : 0; - else - { - WND* wndPtr = WIN_FindWndPtr(menu->hWnd); - - ht = ( ht == HTSYSMENU ) ? (UINT)(wndPtr->hSysMenu) - : ( ht == HTMENU ) ? (UINT)(wndPtr->wIDmenu) : 0; - } - } - return (HMENU)ht; -} - -/*********************************************************************** - * MENU_ExecFocusedItem - * - * Execute a menu item (for instance when user pressed Enter). - * Return TRUE if we can go on with menu tracking. - */ - WINBOOL MENU_ExecFocusedItem( MTRACKER* pmt, HMENU hMenu ) -{ - MENUITEM *item; - POPUPMENU *menu = (POPUPMENU *) ( hMenu ); - if (!menu || !menu->nItems || - (menu->FocusedItem == NO_SELECTED_ITEM)) return TRUE; - - item = &menu->items[menu->FocusedItem]; - -// DPRINT( "%08x %08x %08x\n", -// hMenu, item->wID, item->hSubMenu); - - if (!(item->fType & MF_POPUP)) - { - if (!(item->fState & (MF_GRAYED | MF_DISABLED))) - { - if( menu->wFlags & MF_SYSMENU ) - { - PostMessageA( pmt->hOwnerWnd, WM_SYSCOMMAND, item->wID, - MAKELPARAM((INT)pmt->pt.x, (INT)pmt->pt.y) ); - } - else - PostMessageA( pmt->hOwnerWnd, WM_COMMAND, item->wID, 0 ); - return FALSE; - } - else return TRUE; - } - else - { - pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hMenu, TRUE ); - return TRUE; - } -} - - -/*********************************************************************** - * MENU_SwitchTracking - * - * Helper function for menu navigation routines. - */ - void MENU_SwitchTracking( MTRACKER* pmt, HMENU hPtMenu, UINT id ) -{ - POPUPMENU *ptmenu = (POPUPMENU *) ( hPtMenu ); - POPUPMENU *topmenu = (POPUPMENU *) ( pmt->hTopMenu ); - - if( pmt->hTopMenu != hPtMenu && - !((ptmenu->wFlags | topmenu->wFlags) & MF_POPUP) ) - { - /* both are top level menus (system and menu-bar) */ - - MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE ); - MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE ); - pmt->hTopMenu = hPtMenu; - } - else MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, FALSE ); - MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, id, TRUE ); -} - - -/*********************************************************************** - * MENU_ButtonDown - * - * Return TRUE if we can go on with menu tracking. - */ - WINBOOL MENU_ButtonDown( MTRACKER* pmt, HMENU hPtMenu ) -{ - if (hPtMenu) - { - UINT id = 0; - POPUPMENU *ptmenu = (POPUPMENU *) ( hPtMenu ); - MENUITEM *item; - - if( IS_SYSTEM_MENU(ptmenu) ) - item = ptmenu->items; - else - item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id ); - - if( item ) - { - if( ptmenu->FocusedItem == id ) - { - /* nothing to do with already selected non-popup */ - if( !(item->fType & MF_POPUP) ) return TRUE; - - if( item->fState & MF_MOUSESELECT ) - { - if( ptmenu->wFlags & MF_POPUP ) - { - /* hide selected subpopup */ - - MENU_HideSubPopups( pmt->hOwnerWnd, hPtMenu, TRUE ); - pmt->hCurrentMenu = hPtMenu; - return TRUE; - } - return FALSE; /* shouldn't get here */ - } - } - else MENU_SwitchTracking( pmt, hPtMenu, id ); - - /* try to display a subpopup */ - - pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE ); - return TRUE; - } - else DPRINT("\tunable to find clicked item!\n"); - } - return FALSE; -} - - - - - - - -/*********************************************************************** - * MENU_TrackMenu - * - * Menu tracking code. - */ - WINBOOL MENU_TrackMenu( HMENU hmenu, UINT wFlags, INT x, INT y, - HWND hwnd, const RECT *lprect ) -{ - MSG msg; - POPUPMENU *menu; - WINBOOL fRemove; - MTRACKER mt = { 0, hmenu, hmenu, hwnd, {x, y} }; /* control struct */ - - fEndMenu = FALSE; - if (!(menu = (POPUPMENU *) ( hmenu ))) return FALSE; - - if (wFlags & TPM_BUTTONDOWN) MENU_ButtonDown( &mt, hmenu ); - - EVENT_Capture( mt.hOwnerWnd, HTMENU ); - - while (!fEndMenu) - { - menu = (POPUPMENU *) ( mt.hCurrentMenu ); - msg.hwnd = (wFlags & TPM_ENTERIDLEEX && menu->wFlags & MF_POPUP) ? menu->hWnd : 0; - - /* we have to keep the message in the queue until it's - * clear that menu loop is not over yet. */ - - if (!MSG_InternalGetMessage( &msg, msg.hwnd, mt.hOwnerWnd, - MSGF_MENU, PM_NOREMOVE, TRUE )) break; - - TranslateMessage( &msg ); - memcpy( &msg.pt, &mt.pt ,sizeof(POINT)); - - fRemove = FALSE; - if ((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST)) - { - /* Find a menu for this mouse event */ - - hmenu = MENU_PtMenu( mt.hTopMenu, msg.pt ); - - switch(msg.message) - { - /* no WM_NC... messages in captured state */ - - case WM_RBUTTONDBLCLK: - case WM_RBUTTONDOWN: - if (!(wFlags & TPM_RIGHTBUTTON)) break; - /* fall through */ - case WM_LBUTTONDBLCLK: - case WM_LBUTTONDOWN: - fEndMenu |= !MENU_ButtonDown( &mt, hmenu ); - break; - - case WM_RBUTTONUP: - if (!(wFlags & TPM_RIGHTBUTTON)) break; - /* fall through */ - case WM_LBUTTONUP: - /* If outside all menus but inside lprect, ignore it */ - if (hmenu || !lprect || !PtInRect(lprect, mt.pt)) - { - fEndMenu |= !MENU_ButtonUp( &mt, hmenu ); - fRemove = TRUE; - } - break; - - case WM_MOUSEMOVE: - if ((msg.wParam & MK_LBUTTON) || ((wFlags & TPM_RIGHTBUTTON) - && (msg.wParam & MK_RBUTTON))) - { - fEndMenu |= !MENU_MouseMove( &mt, hmenu ); - } - } /* switch(msg.message) - mouse */ - } - else if ((msg.message >= WM_KEYFIRST) && (msg.message <= WM_KEYLAST)) - { - fRemove = TRUE; /* Keyboard messages are always removed */ - switch(msg.message) - { - case WM_KEYDOWN: - switch(msg.wParam) - { - case VK_HOME: - case VK_END: - MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, - NO_SELECTED_ITEM, FALSE ); - /* fall through */ - case VK_UP: - MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, - (msg.wParam == VK_HOME)? ITEM_NEXT : ITEM_PREV ); - break; - - case VK_DOWN: /* If on menu bar, pull-down the menu */ - - menu = (POPUPMENU *) ( mt.hCurrentMenu ); - if (!(menu->wFlags & MF_POPUP)) - mt.hCurrentMenu = MENU_ShowSubPopup( mt.hOwnerWnd, mt.hTopMenu, TRUE ); - else /* otherwise try to move selection */ - MENU_MoveSelection( mt.hOwnerWnd, mt.hCurrentMenu, ITEM_NEXT ); - break; - - case VK_LEFT: - MENU_KeyLeft( &mt ); - break; - - case VK_RIGHT: - MENU_KeyRight( &mt ); - break; - - case VK_ESCAPE: - fEndMenu = TRUE; - break; - - default: - break; - } - break; /* WM_KEYDOWN */ - - case WM_SYSKEYDOWN: - switch(msg.wParam) - { - case VK_MENU: - fEndMenu = TRUE; - break; - - } - break; /* WM_SYSKEYDOWN */ - - case WM_CHAR: - { - UINT pos; - - if (msg.wParam == '\r' || msg.wParam == ' ') - { - fEndMenu |= !MENU_ExecFocusedItem( &mt, mt.hCurrentMenu ); - break; - } - - /* Hack to avoid control chars. */ - /* We will find a better way real soon... */ - if ((msg.wParam <= 32) || (msg.wParam >= 127)) break; - - pos = MENU_FindItemByKey( mt.hOwnerWnd, mt.hCurrentMenu, - msg.wParam, FALSE ); - if (pos == (UINT)-2) fEndMenu = TRUE; - else if (pos == (UINT)-1) MessageBeep(0); - else - { - MENU_SelectItem( mt.hOwnerWnd, mt.hCurrentMenu, pos, TRUE ); - fEndMenu |= !MENU_ExecFocusedItem( &mt, mt.hCurrentMenu ); - } - } - break; - } /* switch(msg.message) - kbd */ - } - else - { - DispatchMessageA( &msg ); - } - - if (!fEndMenu) fRemove = TRUE; - - /* finally remove message from the queue */ - - if (fRemove && !(mt.trackFlags & TF_SKIPREMOVE) ) - PeekMessageA( &msg, 0, msg.message, msg.message, PM_REMOVE ); - else mt.trackFlags &= ~TF_SKIPREMOVE; - } - - ReleaseCapture(); - if( IsWindow( mt.hOwnerWnd ) ) - { - MENU_HideSubPopups( mt.hOwnerWnd, mt.hTopMenu, FALSE ); - - menu = (POPUPMENU *) ( mt.hTopMenu ); - if (menu && menu->wFlags & MF_POPUP) - { - ShowWindow( menu->hWnd, SW_HIDE ); - uSubPWndLevel = 0; - } - MENU_SelectItem( mt.hOwnerWnd, mt.hTopMenu, NO_SELECTED_ITEM, FALSE ); - SendMessageW( mt.hOwnerWnd, WM_MENUSELECT, 0, MAKELONG( 0xffff, 0 ) ); - } - fEndMenu = FALSE; - return TRUE; -} - - - - - -/*********************************************************************** - * MENU_ButtonUp - * - * Return TRUE if we can go on with menu tracking. - */ - WINBOOL MENU_ButtonUp( MTRACKER* pmt, HMENU hPtMenu ) -{ - if (hPtMenu) - { - UINT id = 0; - POPUPMENU *ptmenu = (POPUPMENU *) ( hPtMenu ); - MENUITEM *item; - - if( IS_SYSTEM_MENU(ptmenu) ) - item = ptmenu->items; - else - item = MENU_FindItemByCoords( ptmenu, pmt->pt, &id ); - - if( item && (ptmenu->FocusedItem == id )) - { - if( !(item->fType & MF_POPUP) ) - return MENU_ExecFocusedItem( pmt, hPtMenu ); - hPtMenu = item->hSubMenu; - if( hPtMenu == pmt->hCurrentMenu ) - { - /* Select first item of sub-popup */ - - MENU_SelectItem( pmt->hOwnerWnd, hPtMenu, NO_SELECTED_ITEM, FALSE ); - MENU_MoveSelection( pmt->hOwnerWnd, hPtMenu, ITEM_NEXT ); - } - return TRUE; - } - } - return FALSE; -} - - -/*********************************************************************** - * MENU_MouseMove - * - * Return TRUE if we can go on with menu tracking. - */ - WINBOOL MENU_MouseMove( MTRACKER* pmt, HMENU hPtMenu ) -{ - UINT id = NO_SELECTED_ITEM; - POPUPMENU *ptmenu = NULL; - - if( hPtMenu ) - { - ptmenu = (POPUPMENU *) ( hPtMenu ); - if( IS_SYSTEM_MENU(ptmenu) ) - id = 0; - else - MENU_FindItemByCoords( ptmenu, pmt->pt, &id ); - } - - if( id == NO_SELECTED_ITEM ) - { - MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu, - NO_SELECTED_ITEM, TRUE ); - } - else if( ptmenu->FocusedItem != id ) - { - MENU_SwitchTracking( pmt, hPtMenu, id ); - pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hPtMenu, FALSE ); - } - return TRUE; -} - - -/*********************************************************************** - * MENU_DoNextMenu - * - * NOTE: WM_NEXTMENU documented in Win is a bit different. - */ - LRESULT MENU_DoNextMenu( MTRACKER* pmt, UINT vk ) -{ - POPUPMENU *menu = (POPUPMENU *) ( pmt->hTopMenu ); - - if( (vk == VK_LEFT && menu->FocusedItem == 0 ) || - (vk == VK_RIGHT && menu->FocusedItem == menu->nItems - 1)) - { - WND* wndPtr; - HMENU hNewMenu; - HWND hNewWnd; - UINT id = 0; - MDINEXTMENU MdiNextMenu; - LRESULT l; - - MdiNextMenu.hmenuIn = menu; - if (IS_SYSTEM_MENU(menu)) - MdiNextMenu.hmenuNext = GetSubMenu(pmt->hTopMenu,0); - else - MdiNextMenu.hmenuNext = pmt->hTopMenu; - - MdiNextMenu.hwndNext = pmt->hOwnerWnd; - - l = SendMessageW( pmt->hOwnerWnd, WM_NEXTMENU, (WPARAM)vk, &MdiNextMenu); - - if( l == 0 ) - { - wndPtr = WIN_FindWndPtr(pmt->hOwnerWnd); - - hNewWnd = pmt->hOwnerWnd; - if( IS_SYSTEM_MENU(menu) ) - { - /* switch to the menu bar */ - - if( ((wndPtr->dwStyle & WS_CHILD) == WS_CHILD) || !wndPtr->wIDmenu ) - return FALSE; - - hNewMenu = (HMENU)wndPtr->wIDmenu; - if( vk == VK_LEFT ) - { - menu = (POPUPMENU *) ( hNewMenu ); - id = menu->nItems - 1; - } - } - else if( (( wndPtr->dwStyle & WS_SYSMENU) == WS_SYSMENU ) ) - { - /* switch to the system menu */ - hNewMenu = wndPtr->hSysMenu; - } - else return FALSE; - } - else /* application returned a new menu to switch to */ - { - hNewMenu = MdiNextMenu.hmenuNext; - hNewWnd = MdiNextMenu.hwndNext; - - if( IsMenu(hNewMenu) && IsWindow(hNewWnd) ) - { - wndPtr = WIN_FindWndPtr(hNewWnd); - - if( ( (wndPtr->dwStyle & WS_SYSMENU) == WS_SYSMENU ) && - GetSubMenu(wndPtr->hSysMenu, 0) == hNewMenu ) - { - /* get the real system menu */ - hNewMenu = wndPtr->hSysMenu; - } - else if( ((wndPtr->dwStyle & WS_CHILD) == WS_CHILD) || (HANDLE)wndPtr->wIDmenu != hNewMenu ) - { - /* FIXME: Not sure what to do here, perhaps, - * try to track hNewMenu as a popup? */ - - //DPRINT(" -- got confused.\n"); - return FALSE; - } - } - else return FALSE; - } - - if( hNewMenu != pmt->hTopMenu ) - { - MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, NO_SELECTED_ITEM, FALSE ); - if( pmt->hCurrentMenu != pmt->hTopMenu ) - MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE ); - } - - if( hNewWnd != pmt->hOwnerWnd ) - { - ReleaseCapture(); - pmt->hOwnerWnd = hNewWnd; - EVENT_Capture( pmt->hOwnerWnd, HTMENU ); - } - - pmt->hTopMenu = pmt->hCurrentMenu = hNewMenu; /* all subpopups are hidden */ - MENU_SelectItem( pmt->hOwnerWnd, pmt->hTopMenu, id, TRUE ); - - return TRUE; - } - return FALSE; -} - -/*********************************************************************** - * MENU_SuspendPopup - * - * The idea is not to show the popup if the next input message is - * going to hide it anyway. - */ -WINBOOL MENU_SuspendPopup( MTRACKER* pmt, UINT uMsg ) -{ - MSG msg; - - msg.hwnd = pmt->hOwnerWnd; - - PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE); - pmt->trackFlags |= TF_SKIPREMOVE; - - switch( uMsg ) - { - case WM_KEYDOWN: - PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE); - if( msg.message == WM_KEYUP || msg.message == WM_PAINT ) - { - PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_REMOVE); - PeekMessageA( &msg, 0, 0, 0, PM_NOYIELD | PM_NOREMOVE); - if( msg.message == WM_KEYDOWN && - (msg.wParam == VK_LEFT || msg.wParam == VK_RIGHT)) - { - pmt->trackFlags |= TF_SUSPENDPOPUP; - return TRUE; - } - } - break; - } - - /* failures go through this */ - pmt->trackFlags &= ~TF_SUSPENDPOPUP; - return FALSE; -} - -/*********************************************************************** - * MENU_KeyLeft - * - * Handle a VK_LEFT key event in a menu. - */ -void MENU_KeyLeft( MTRACKER* pmt ) -{ - POPUPMENU *menu; - HMENU hmenutmp, hmenuprev; - UINT prevcol; - - hmenuprev = hmenutmp = pmt->hTopMenu; - menu = (POPUPMENU *) ( hmenutmp ); - - /* Try to move 1 column left (if possible) */ - if( (prevcol = MENU_GetStartOfPrevColumn( pmt->hCurrentMenu )) != - NO_SELECTED_ITEM ) { - - MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu, - prevcol, TRUE ); - return; - } - - /* close topmost popup */ - while (hmenutmp != pmt->hCurrentMenu) - { - hmenuprev = hmenutmp; - hmenutmp = MENU_GetSubPopup( hmenuprev ); - } - - MENU_HideSubPopups( pmt->hOwnerWnd, hmenuprev, TRUE ); - pmt->hCurrentMenu = hmenuprev; - - if ( (hmenuprev == pmt->hTopMenu) && !(menu->wFlags & MF_POPUP) ) - { - /* move menu bar selection if no more popups are left */ - - if( !MENU_DoNextMenu( pmt, VK_LEFT) ) - MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_PREV ); - - if ( hmenuprev != hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP ) - { - /* A sublevel menu was displayed - display the next one - * unless there is another displacement coming up */ - - if( !MENU_SuspendPopup( pmt, WM_KEYDOWN ) ) - pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, - pmt->hTopMenu, TRUE ); - } - } -} - - -/*********************************************************************** - * MENU_KeyRight - * - * Handle a VK_RIGHT key event in a menu. - */ -void MENU_KeyRight( MTRACKER* pmt ) -{ - HMENU hmenutmp; - POPUPMENU *menu = (POPUPMENU *) ( pmt->hTopMenu ); - UINT nextcol; - -// DPRINT( "MENU_KeyRight called, cur %x (%s), top %x (%s).\n", -// pmt->hCurrentMenu, -// ((POPUPMENU *)(pmt->hCurrentMenu))-> -// items[0].text, -// pmt->hTopMenu, menu->items[0].text ); - - if ( (menu->wFlags & MF_POPUP) || (pmt->hCurrentMenu != pmt->hTopMenu)) - { - /* If already displaying a popup, try to display sub-popup */ - - hmenutmp = pmt->hCurrentMenu; - pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, hmenutmp, TRUE ); - - /* if subpopup was displayed then we are done */ - if (hmenutmp != pmt->hCurrentMenu) return; - } - - /* Check to see if there's another column */ - if( (nextcol = MENU_GetStartOfNextColumn( pmt->hCurrentMenu )) != - NO_SELECTED_ITEM ) { -// DPRINT( "Going to %d.\n", nextcol ); - MENU_SelectItem( pmt->hOwnerWnd, pmt->hCurrentMenu, - nextcol, TRUE ); - return; - } - - if (!(menu->wFlags & MF_POPUP)) /* menu bar tracking */ - { - if( pmt->hCurrentMenu != pmt->hTopMenu ) - { - MENU_HideSubPopups( pmt->hOwnerWnd, pmt->hTopMenu, FALSE ); - hmenutmp = pmt->hCurrentMenu = pmt->hTopMenu; - } else hmenutmp = 0; - - /* try to move to the next item */ - if( !MENU_DoNextMenu( pmt, VK_RIGHT) ) - MENU_MoveSelection( pmt->hOwnerWnd, pmt->hTopMenu, ITEM_NEXT ); - - if( hmenutmp || pmt->trackFlags & TF_SUSPENDPOPUP ) - if( !MENU_SuspendPopup(pmt, WM_KEYDOWN) ) - pmt->hCurrentMenu = MENU_ShowSubPopup( pmt->hOwnerWnd, - pmt->hTopMenu, TRUE ); - } -} - - - - -/*********************************************************************** - * MENU_InitTracking - */ -WINBOOL MENU_InitTracking(HWND hWnd, HMENU hMenu) -{ - HideCaret(0); - SendMessageW( hWnd, WM_ENTERMENULOOP, (WPARAM)0, (LPARAM)0 ); - SendMessageW( hWnd, WM_SETCURSOR, (WPARAM)hWnd, (LPARAM)HTCAPTION ); - SendMessageW( hWnd, WM_INITMENU, (WPARAM)hMenu, (LPARAM)0 ); - return TRUE; -} - -/*********************************************************************** - * MENU_TrackMouseMenuBar - * - * Menu-bar tracking upon a mouse event. Called from NC_HandleSysCommand(). - */ -void MENU_TrackMouseMenuBar( WND* wndPtr, INT ht, POINT pt ) -{ - HWND hWnd = (HWND)(wndPtr->hwndSelf); - HMENU hMenu = ((ht == (HTSYSMENU)) ? (HMENU)wndPtr->hSysMenu : (HMENU)wndPtr->wIDmenu); - - if (IsMenu(hMenu)) - { - MENU_InitTracking( hWnd, hMenu ); - MENU_TrackMenu( hMenu, TPM_ENTERIDLEEX | TPM_BUTTONDOWN | - TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, hWnd, NULL ); - - SendMessageW( hWnd, WM_EXITMENULOOP,(WPARAM)0,(LPARAM)0 ); - ShowCaret(0); - } -} - - - - -/*********************************************************************** - * MENU_TrackKbdMenuBar - * - * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand(). - */ -void MENU_TrackKbdMenuBar( WND* wndPtr, UINT wParam, INT vkey) -{ - UINT uItem = NO_SELECTED_ITEM; - HMENU hTrackMenu; - - /* find window that has a menu */ - - while( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwStyle & WS_SYSMENU) ) - if( !(wndPtr = wndPtr->parent) ) return; - - /* check if we have to track a system menu */ - - if( (wndPtr->dwStyle & (WS_CHILD | WS_MINIMIZE)) || - !wndPtr->wIDmenu || vkey == VK_SPACE ) - { - if( !(wndPtr->dwStyle & WS_SYSMENU) ) return; - hTrackMenu = wndPtr->hSysMenu; - uItem = 0; - wParam |= HTSYSMENU; /* prevent item lookup */ - } - else - hTrackMenu = (HANDLE)wndPtr->wIDmenu; - - if (IsMenu( hTrackMenu )) - { - MENU_InitTracking( wndPtr->hwndSelf, hTrackMenu ); - - if( vkey && vkey != VK_SPACE ) - { - uItem = MENU_FindItemByKey( wndPtr->hwndSelf, hTrackMenu, - vkey, (wParam & HTSYSMENU) ); - if( uItem >= (UINT)(-2) ) - { - if( uItem == (UINT)(-1) ) MessageBeep(0); - hTrackMenu = 0; - } - } - - if( hTrackMenu ) - { - MENU_SelectItem( wndPtr->hwndSelf, hTrackMenu, uItem, TRUE ); - - if( uItem == NO_SELECTED_ITEM ) - MENU_MoveSelection( wndPtr->hwndSelf, hTrackMenu, ITEM_NEXT ); - else if( vkey ) - PostMessage( wndPtr->hwndSelf, WM_KEYDOWN, VK_DOWN, 0L ); - - MENU_TrackMenu( hTrackMenu, TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON, - 0, 0, wndPtr->hwndSelf, NULL ); - } - SendMessage( wndPtr->hwndSelf, WM_EXITMENULOOP, 0, 0 ); - ShowCaret(0); - } -} - -#if 0 - - -/*********************************************************************** - * MENU_TrackKbdMenuBar - * - * Menu-bar tracking upon a keyboard event. Called from NC_HandleSysCommand(). - */ -void MENU_TrackMouseMenuBar( WND* wndPtr, INT ht, POINT pt ) -{ - UINT uItem = NO_SELECTED_ITEM; - HMENU hTrackMenu; - - /* find window that has a menu */ - - while( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwStyle & WS_SYSMENU) ) - if( !(wndPtr = wndPtr->parent) ) return; - - /* check if we have to track a system menu */ - - if( (wndPtr->dwStyle & (WS_CHILD | WS_MINIMIZE)) || - !wndPtr->wIDmenu || vkey == VK_SPACE ) - { - if( !(wndPtr->dwStyle & WS_SYSMENU) ) return; - hTrackMenu = wndPtr->hSysMenu; - uItem = 0; - wParam |= HTSYSMENU; /* prevent item lookup */ - } - else - hTrackMenu = (HANDLE)wndPtr->wIDmenu; - - if (IsMenu( hTrackMenu )) - { - MENU_InitTracking( wndPtr->hwndSelf, hTrackMenu ); - - if( vkey && vkey != VK_SPACE ) - { - uItem = MENU_FindItemByKey( wndPtr->hwndSelf, hTrackMenu, - vkey, (wParam & HTSYSMENU) ); - if( uItem >= (UINT)(-2) ) - { - if( uItem == (UINT)(-1) ) MessageBeep(0); - hTrackMenu = 0; - } - } - - if( hTrackMenu ) - { - MENU_SelectItem( wndPtr->hwndSelf, hTrackMenu, uItem, TRUE ); - - if( uItem == NO_SELECTED_ITEM ) - MENU_MoveSelection( wndPtr->hwndSelf, hTrackMenu, ITEM_NEXT ); - else if( vkey ) - PostMessageA( wndPtr->hwndSelf, WM_KEYDOWN, VK_DOWN, 0L ); - - MENU_TrackMenu( hTrackMenu, TPM_ENTERIDLEEX | TPM_LEFTALIGN | TPM_LEFTBUTTON, - 0, 0, wndPtr->hwndSelf, NULL ); - } - SendMessageW( wndPtr->hwndSelf, WM_EXITMENULOOP, 0, 0 ); - ShowCaret(0); - } -} - -#endif \ No newline at end of file diff --git a/reactos/lib/user32/internal/msg.c b/reactos/lib/user32/internal/msg.c deleted file mode 100644 index f2c98fda3c2..00000000000 --- a/reactos/lib/user32/internal/msg.c +++ /dev/null @@ -1,1178 +0,0 @@ -/* - * Message queues related functions - * - * Copyright 1993, 1994 Alexandre Julliard - */ - - -#include -#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int abs(int x); - -UINT doubleClickSpeed = 452; -INT debugSMRL = 0; /* intertask SendMessage() recursion level */ - -/*********************************************************************** - * MSG_CheckFilter - */ -WINBOOL MSG_CheckFilter(WORD uMsg, DWORD filter) -{ - if( filter ) - return (uMsg >= LOWORD(filter) && uMsg <= HIWORD(filter)); - return TRUE; -} - -/*********************************************************************** - * MSG_SendParentNotify - * - * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless - * the window has the WS_EX_NOPARENTNOTIFY style. - */ -void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue) -{ -#define lppt ((LPPOINT)&lValue) - - /* pt has to be in the client coordinates of the parent window */ - - MapWindowPoints( 0, wndPtr->hwndSelf, lppt, 1 ); - while (wndPtr) - { - if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break; - lppt->x += wndPtr->rectClient.left; - lppt->y += wndPtr->rectClient.top; - wndPtr = wndPtr->parent; - SendMessageW( wndPtr->hwndSelf, WM_PARENTNOTIFY, - MAKEWPARAM( event, idChild ), lValue ); - } -#undef lppt -} - - -/*********************************************************************** - * MSG_TranslateMouseMsg - * - * Translate an mouse hardware event into a real mouse message. - * Return value indicates whether the translated message must be passed - * to the user, left in the queue, or skipped entirely (in this case - * HIWORD contains hit test code). - */ -DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD filter, - MSG *msg, WINBOOL remove, WND* pWndScope ) -{ - DWORD dblclk_time_limit = 0; - UINT clk_message = 0; - HWND clk_hwnd = 0; - POINT clk_pos = { 0, 0 }; - - WND *pWnd; - HWND hWnd; - INT ht, hittest, sendSC = 0; - UINT message = msg->message; - POINT screen_pt, pt; - HANDLE hQ = GetFastQueue(); - MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock(hQ); - WINBOOL eatMsg = FALSE; - WINBOOL mouseClick = ((message == WM_LBUTTONDOWN) || - (message == WM_RBUTTONDOWN) || - (message == WM_MBUTTONDOWN))?1:0; - SYSQ_STATUS ret = 0; - - /* Find the window */ - - ht = hittest = HTCLIENT; - hWnd = GetCapture(); - if( !hWnd ) - { - ht = hittest = WINPOS_WindowFromPoint( pWndScope, msg->pt, &pWnd ); - if( !pWnd ) pWnd = WIN_GetDesktop(); - hWnd = pWnd->hwndSelf; - sendSC = 1; - } - else - { - pWnd = WIN_FindWndPtr(hWnd); - ht = EVENT_GetCaptureInfo(); - } - - /* stop if not the right queue */ - - if (pWnd->hmemTaskQ != hQ) - { - /* Not for the current task */ - if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE ); - /* Wake up the other task */ - queue = (MESSAGEQUEUE *)GlobalLock( pWnd->hmemTaskQ ); - if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE ); - return SYSQ_MSG_ABANDON; - } - - /* check if hWnd is within hWndScope */ - - if( hTopWnd && hWnd != hTopWnd ) - if( !IsChild(hTopWnd, hWnd) ) return SYSQ_MSG_CONTINUE; - - if( mouseClick ) - { - /* translate double clicks - - * note that ...MOUSEMOVEs can slip in between - * ...BUTTONDOWN and ...BUTTONDBLCLK messages */ - - if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT ) - { - if ((message == clk_message) && (hWnd == clk_hwnd) && - (msg->time - dblclk_time_limit < doubleClickSpeed) && - (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) && - (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2)) - { - message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); - mouseClick++; /* == 2 */ - } - } - } - screen_pt = pt = msg->pt; - - if (hittest != HTCLIENT) - { - message += ((INT)WM_NCMOUSEMOVE - WM_MOUSEMOVE); - msg->wParam = hittest; - } - else ScreenToClient( hWnd, &pt ); - - /* check message filter */ - - if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE; - - pCursorQueue = queue; - - /* call WH_MOUSE */ - - if (HOOK_IsHooked( WH_MOUSE )) - { - MOUSEHOOKSTRUCT *hook = HeapAlloc(GetProcessHeap(),0,sizeof(MOUSEHOOKSTRUCT)); - if( hook ) - { - hook->pt = screen_pt; - hook->hwnd = hWnd; - hook->wHitTestCode = hittest; - hook->dwExtraInfo = 0; - ret = HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE, - message, (LPARAM)(hook), pWnd->class->bUnicode ); - HeapFree(GetProcessHeap(),0,hook); - } - if( ret ) return MAKELONG((INT)SYSQ_MSG_SKIP, hittest); - } - - if ((hittest == HTERROR) || (hittest == HTNOWHERE)) - eatMsg = sendSC = 1; - else if( remove && mouseClick ) - { - HWND hwndTop = WIN_GetTopParent( hWnd ); - - if( mouseClick == 1 ) - { - /* set conditions */ - dblclk_time_limit = msg->time; - clk_message = msg->message; - clk_hwnd = hWnd; - clk_pos = screen_pt; - } else - /* got double click - zero them out */ - dblclk_time_limit = clk_hwnd = 0; - - if( sendSC ) - { - /* Send the WM_PARENTNOTIFY, - * note that even for double/nonclient clicks - * notification message is still WM_L/M/RBUTTONDOWN. - */ - - MSG_SendParentNotify( pWnd, msg->message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) ); - - /* Activate the window if needed */ - - if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow()) - { - LONG ret = SendMessageW( hWnd, WM_MOUSEACTIVATE,(WPARAM) hwndTop, - (LPARAM)MAKELONG( hittest, message ) ); - - if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT)) - eatMsg = TRUE; - - if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT)) - && hwndTop != GetActiveWindow() ) - if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE )) - eatMsg = TRUE; - } - } - } else sendSC = (remove && sendSC); - - /* Send the WM_SETCURSOR message */ - - if (sendSC) - SendMessageW( hWnd, WM_SETCURSOR, (WPARAM)hWnd, - MAKELONG( hittest, message )); - if (eatMsg) return MAKELONG( (UINT)SYSQ_MSG_SKIP, hittest); - - msg->hwnd = hWnd; - msg->message = message; - msg->lParam = MAKELONG( pt.x, pt.y ); - return SYSQ_MSG_ACCEPT; -} - - -/*********************************************************************** - * MSG_TranslateKbdMsg - * - * Translate an keyboard hardware event into a real message. - */ -DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD filter, - MSG *msg, WINBOOL remove ) -{ - WORD message = msg->message; - HWND hWnd = GetFocus(); - WND *pWnd; - - /* Should check Ctrl-Esc and PrintScreen here */ - - if (!hWnd) - { - /* Send the message to the active window instead, */ - /* translating messages to their WM_SYS equivalent */ - - hWnd = GetActiveWindow(); - - if( message < WM_SYSKEYDOWN ) - message += WM_SYSKEYDOWN - WM_KEYDOWN; - } - pWnd = WIN_FindWndPtr( hWnd ); - if (pWnd && (pWnd->hmemTaskQ != GetFastQueue())) - { - /* Not for the current task */ - MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock( GetFastQueue() ); - if (queue) QUEUE_ClearWakeBit( queue, QS_KEY ); - /* Wake up the other task */ - queue = (MESSAGEQUEUE *)GlobalLock( pWnd->hmemTaskQ ); - if (queue) QUEUE_SetWakeBit( queue, QS_KEY ); - return SYSQ_MSG_ABANDON; - } - - if (hTopWnd && hWnd != hTopWnd) - if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE; - if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE; - - msg->hwnd = hWnd; - msg->message = message; - - return (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE, - msg->wParam, msg->lParam ) - ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT); -} - - -/*********************************************************************** - * MSG_JournalRecordMsg - * - * Build an EVENTMSG structure and call JOURNALRECORD hook - */ -void MSG_JournalRecordMsg( MSG *msg ) -{ - EVENTMSG *event = HeapAlloc(GetProcessHeap(),0,sizeof(EVENTMSG)); - if (!event) return; - event->message = msg->message; - event->time = msg->time; - if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST)) - { - event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8); - event->paramH = msg->lParam & 0x7FFF; - if (HIWORD(msg->lParam) & 0x0100) - event->paramH |= 0x8000; /* special_key - bit */ - HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, - (LPARAM)(event) ); - } - else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST)) - { - event->paramL = LOWORD(msg->lParam); /* X pos */ - event->paramH = HIWORD(msg->lParam); /* Y pos */ - ClientToScreen( msg->hwnd, (LPPOINT)&event->paramL ); - HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, - (LPARAM)(event) ); - } - else if ((msg->message >= WM_NCMOUSEFIRST) && - (msg->message <= WM_NCMOUSELAST)) - { - event->paramL = LOWORD(msg->lParam); /* X pos */ - event->paramH = HIWORD(msg->lParam); /* Y pos */ - event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */ - HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, - (LPARAM)(event) ); - } - HeapFree(GetProcessHeap(),0,event); -} - -/*********************************************************************** - * MSG_JournalPlayBackMsg - * - * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function - */ -int MSG_JournalPlayBackMsg(void) -{ - EVENTMSG *tmpMsg; - long wtime,lParam; - WORD keyDown,i,wParam,result=0; - - if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) ) - { - tmpMsg = HeapAlloc(GetProcessHeap(),0,sizeof(EVENTMSG)); - wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, - (LPARAM)(tmpMsg)); - /* DPRINT("Playback wait time =%ld\n",wtime); */ - if (wtime<=0) - { - wtime=0; - if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST)) - { - wParam=tmpMsg->paramL & 0xFF; - lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8); - if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN) - { - for (keyDown=i=0; i<256 && !keyDown; i++) - if (InputKeyStateTable[i] & 0x80) - keyDown++; - if (!keyDown) - lParam |= 0x40000000; - AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80; - } - else /* WM_KEYUP, WM_SYSKEYUP */ - { - lParam |= 0xC0000000; - AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80; - } - if (InputKeyStateTable[VK_MENU] & 0x80) - lParam |= 0x20000000; - if (tmpMsg->paramH & 0x8000) /*special_key bit*/ - lParam |= 0x01000000; - hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 ); - } - else - { - if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST)) - { - switch (tmpMsg->message) - { - case WM_LBUTTONDOWN: - MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break; - case WM_LBUTTONUP: - MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break; - case WM_MBUTTONDOWN: - MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break; - case WM_MBUTTONUP: - MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break; - case WM_RBUTTONDOWN: - MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break; - case WM_RBUTTONUP: - MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break; - } - AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0; - AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0; - AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0; - SetCursorPos(tmpMsg->paramL,tmpMsg->paramH); - lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH); - wParam=0; - if (MouseButtonsStates[0]) wParam |= MK_LBUTTON; - if (MouseButtonsStates[1]) wParam |= MK_MBUTTON; - if (MouseButtonsStates[2]) wParam |= MK_RBUTTON; - hardware_event( tmpMsg->message, wParam, lParam, - tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 ); - } - } - HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, - (LPARAM)(tmpMsg)); - } - else - { - if( tmpMsg->message == WM_QUEUESYNC ) - if (HOOK_IsHooked( WH_CBT )) - HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L); - - result= QS_MOUSE | QS_KEY; /* ? */ - } - HeapFree(GetProcessHeap(),0,tmpMsg); - } - return result; -} - -/*********************************************************************** - * MSG_PeekHardwareMsg - * - * Peek for a hardware message matching the hwnd and message filters. - */ -WINBOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD filter, - WINBOOL remove ) -{ - DWORD status = SYSQ_MSG_ACCEPT; - MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue(); - int i, kbd_msg, pos = sysMsgQueue->nextMessage; - - /* FIXME: there has to be a better way to do this */ -// joySendMessages(); - - /* If the queue is empty, attempt to fill it */ -//&& THREAD_IsWinA( THREAD_Current() ) - if (!sysMsgQueue->msgCount && EVENT_Pending()) - EVENT_WaitNetEvent( FALSE, FALSE ); - - for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++) - { - if (pos >= sysMsgQueue->queueSize) pos = 0; - *msg = sysMsgQueue->messages[pos].msg; - - /* Translate message */ - - if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST)) - { - HWND hWndScope = (HWND)sysMsgQueue->messages[pos].extraInfo; -// removed Options.managed && - status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove, - ( IsWindow(hWndScope) ) - ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() ); - kbd_msg = 0; - } - else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST)) - { - status = MSG_TranslateKbdMsg(hwnd, filter, msg, remove); - kbd_msg = 1; - } - else /* Non-standard hardware event */ - { - HARDWAREHOOKSTRUCT *hook; - if ( (hook = HeapAlloc(GetProcessHeap(),0,sizeof(HARDWAREHOOKSTRUCT))) ) - { - WINBOOL ret; - hook->hWnd = msg->hwnd; - hook->wMessage = msg->message; - hook->wParam = msg->wParam; - hook->lParam = msg->lParam; - ret = HOOK_CallHooksA( WH_HARDWARE, - remove ? HC_ACTION : HC_NOREMOVE, - 0, (LPARAM)hook ); - HeapFree(GetProcessHeap(),0,hook); - if (ret) - { - QUEUE_RemoveMsg( sysMsgQueue, pos ); - continue; - } - status = SYSQ_MSG_ACCEPT; - } - } - - switch (LOWORD(status)) - { - case SYSQ_MSG_ACCEPT: - break; - - case SYSQ_MSG_SKIP: - if (HOOK_IsHooked( WH_CBT )) - { - if( kbd_msg ) - HOOK_CallHooksA( WH_CBT, HCBT_KEYSKIPPED, - msg->wParam, msg->lParam ); - else - { - MOUSEHOOKSTRUCT *hook = HeapAlloc(GetProcessHeap(),0,sizeof(MOUSEHOOKSTRUCT)); - if (hook) - { - hook->pt = msg->pt; - hook->hwnd = msg->hwnd; - hook->wHitTestCode = HIWORD(status); - hook->dwExtraInfo = 0; - HOOK_CallHooksA( WH_CBT, HCBT_CLICKSKIPPED ,msg->message, - (LPARAM)hook ); - HeapFree(GetProcessHeap(),0,hook); - } - } - } - - if (remove) - QUEUE_RemoveMsg( sysMsgQueue, pos ); - /* continue */ - - case SYSQ_MSG_CONTINUE: - continue; - - case SYSQ_MSG_ABANDON: - return FALSE; - } - - if (remove) - { - if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg ); - QUEUE_RemoveMsg( sysMsgQueue, pos ); - } - return TRUE; - } - return FALSE; -} - - -/*********************************************************************** - * MSG_SendMessage - * - * Implementation of an inter-task SendMessage. - */ -LRESULT MSG_SendMessageInterTask( HWND hwnd, UINT msg, - WPARAM wParam, LPARAM lParam, WINBOOL bUnicode) -{ - - WND *wndPtr; - WND **list, **ppWnd; - INT prevSMRL = debugSMRL; - QSMCTRL qCtrl = { 0, 1}; - MESSAGEQUEUE *queue, *destQ; - - if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST) - { - if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) - return TRUE; - for (ppWnd = list; *ppWnd; ppWnd++) - { - wndPtr = *ppWnd; - //if (!WIN_IsWindow(wndPtr)) - //continue; - if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION) - MSG_SendMessageInterTask( wndPtr->hwndSelf, msg, wParam, lParam, bUnicode ); - } - HeapFree(GetProcessHeap(),0, list ); - return TRUE; - } - - -// should turn queue and destQ around - - if (!(queue = (MESSAGEQUEUE*)GlobalLock( GetFastQueue() ))) return 0; - if (!(destQ = (MESSAGEQUEUE*)GlobalLock( wndPtr->hmemTaskQ ))) return 0; - - //if ( - //IsTaskLocked() || - //!IsWindow(hwnd)) return 0; - - debugSMRL+=4; - DPRINT("%*sSM: %s [%04x] (%04x -> %04x)\n", - prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue ); - - if( !(queue->wakeBits & QS_SMPARAMSFREE) ) - { - DPRINT("\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n"); - QUEUE_WaitBits( QS_SMPARAMSFREE ); - } - - - - - /* resume sending */ - - queue->hWnd = hwnd; - queue->msg = msg; - queue->wParam = LOWORD(wParam); - queue->wParamHigh = HIWORD(wParam); - queue->lParam = lParam; - queue->hPrevSendingTask = destQ->hSendingTask; - destQ->hSendingTask = GetFastQueue(); - - QUEUE_ClearWakeBit( queue, QS_SMPARAMSFREE ); -// queue->flags = (queue->flags & ~(QUEUE_SM_ASCII|QUEUE_SM_UNICODE)) | flags; - - DPRINT("%*ssm: smResultInit = %08x\n", prevSMRL, "", (unsigned)&qCtrl); - - queue->smResultInit = &qCtrl; - - QUEUE_SetWakeBit( destQ, QS_SENDMESSAGE ); - - /* perform task switch and wait for the result */ - - while( qCtrl.bPending ) - { - if (!(queue->wakeBits & QS_SMRESULT)) - { - //if (THREAD_IsWinA( THREAD_Current() )) DirectedYield( destQ->hTask ); - QUEUE_WaitBits( QS_SMRESULT ); - DPRINT("\tsm: have result!\n"); - } - /* got something */ - - DPRINT("%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult ); - - if (queue->smResult) { /* FIXME, smResult should always be set */ - queue->smResult->lResult = queue->SendMessageReturn; - queue->smResult->bPending = FALSE; - } - QUEUE_ClearWakeBit( queue, QS_SMRESULT ); - - if( queue->smResult != &qCtrl ) - DPRINT( "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, ""); - } - queue->smResultInit = NULL; - - DPRINT("%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult); - debugSMRL-=4; - - return qCtrl.lResult; -} - - - -/*********************************************************************** - * MSG_PeekMessage - */ -WINBOOL MSG_PeekMessage( LPMSG msg, HWND hwnd, WORD first, WORD last, - WORD flags, WINBOOL peek ) -{ -#if 0 - case MOUSE_EVENT: - MouseEvent = &Buffer.Event; - if ( MouseEvent->dwEventFlags == MOUSE_MOVED ) { - msg->hwnd = hwnd; - msg->message = WM_MOUSEMOVE; - msg->wParam = MouseEvent->dwControlKeyState; - msg->lParam = - MAKELONG(MouseEvent->dwMousePosition.X,MouseEvent->dwMousePosition.Y); - } - else if ( MouseEvent->dwEventFlags == DOUBLE_CLICK ) { - msg->hwnd = hwnd; - msg->message = WM_MBUTTONDBLCLK; - msg->wParam = MouseEvent->dwControlKeyState; - msg->lParam = - MAKELONG(MouseEvent->dwMousePosition.X,MouseEvent->dwMousePosition.Y); - - } - else { - if (MouseEvent->dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED ) { - msg->hwnd = hwnd; - msg->message = WM_MBUTTONDOWN ; - msg->wParam = MouseEvent->dwControlKeyState; - msg->lParam = - MAKELONG(MouseEvent->dwMousePosition.X,MouseEvent->dwMousePosition.Y); - } - else { - msg->hwnd = hwnd; - msg->message = WM_MBUTTONUP ; - msg->wParam = MouseEvent->dwControlKeyState; - msg->lParam = - MAKELONG(MouseEvent->dwMousePosition.X,MouseEvent->dwMousePosition.Y); - } - } - break; - #endif - - -msg->hwnd = hwnd; -msg->message = WM_MBUTTONDBLCLK; -msg->wParam = 0; -msg->lParam = MAKELONG(200,200); - -return TRUE; - -#if 0 - int pos, mask; - MESSAGEQUEUE *msgQueue; - HQUEUE hQueue; - -#ifdef CONFIG_IPC - DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/ - DDE_GetRemoteMessage(); -#endif /* CONFIG_IPC */ - - mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */ - if (first || last) - { - if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY; - if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) || - ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE; - if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER; - if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER; - if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT; - } - else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT; - - //if (IsTaskLocked()) flags |= PM_NOYIELD; - - /* Never yield on Win32 threads */ -// if (!THREAD_IsWinA(THREAD_Current())) - flags |= PM_NOYIELD; - - while(1) - { - hQueue = GetFastQueue(); - // msgQueue = (MESSAGEQUEUE *)GlobalLock( hQueue ); - msgQueue = (MESSAGEQUEUE *) hQueue; - if (!msgQueue) return FALSE; - msgQueue->changeBits = 0; - - /* First handle a message put by SendMessage() */ - - while (msgQueue->wakeBits & QS_SENDMESSAGE) - QUEUE_ReceiveMessage( msgQueue ); - - /* Now handle a WM_QUIT message */ - - if (msgQueue->wPostQMsg && - (!first || WM_QUIT >= first) && - (!last || WM_QUIT <= last) ) - { - msg->hwnd = hwnd; - msg->message = WM_QUIT; - msg->wParam = msgQueue->wExitCode; - msg->lParam = 0; - if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0; - break; - } - - /* Now find a normal message */ - - if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) && - ((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1)) - { - QMSG *qmsg = &msgQueue->messages[pos]; - *msg = qmsg->msg; - msgQueue->GetMessageTimeVal = msg->time; - msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt; - msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo; - - if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos ); - break; - } - - msgQueue->changeBits |= MSG_JournalPlayBackMsg(); - - /* Now find a hardware event */ - - if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) && - MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE )) - { - /* Got one */ - msgQueue->GetMessageTimeVal = msg->time; - msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt; - msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */ - break; - } - - /* Check again for SendMessage */ - - while (msgQueue->wakeBits & QS_SENDMESSAGE) - QUEUE_ReceiveMessage( msgQueue ); - - /* Now find a WM_PAINT message */ - - if ((msgQueue->wakeBits & mask) & QS_PAINT) - { - WND* wndPtr; - msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue ); - msg->message = WM_PAINT; - msg->wParam = 0; - msg->lParam = 0; - - if ((wndPtr = WIN_FindWndPtr(msg->hwnd))) - { - if( wndPtr->dwStyle & WS_MINIMIZE && - wndPtr->class->hIcon ) - { - msg->message = WM_PAINTICON; - msg->wParam = 1; - } - - if( !hwnd || msg->hwnd == hwnd || IsChild(hwnd,msg->hwnd) ) - { - if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate) - { - wndPtr->flags &= ~WIN_INTERNAL_PAINT; - QUEUE_DecPaintCount( hQueue ); - } - break; - } - } - } - - /* Check for timer messages, but yield first */ - - if (!(flags & PM_NOYIELD)) - { - UserYield(); - while (msgQueue->wakeBits & QS_SENDMESSAGE) - QUEUE_ReceiveMessage( msgQueue ); - } - if ((msgQueue->wakeBits & mask) & QS_TIMER) - { - if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break; - } - - if (peek) - { - if (!(flags & PM_NOYIELD)) UserYield(); - return FALSE; - } - msgQueue->wakeMask = mask; - QUEUE_WaitBits( mask ); - } - - /* We got a message */ - if (flags & PM_REMOVE) - { - WORD message = msg->message; - - if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) - { - BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff]; - - if (!(*p & 0x80)) - *p ^= 0x01; - *p |= 0x80; - } - else if (message == WM_KEYUP || message == WM_SYSKEYUP) - QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80; - } - if (peek) return TRUE; - else return (msg->message != WM_QUIT); - - #endif - -} - -/*********************************************************************** - * MSG_InternalGetMessage - * - * GetMessage() function for internal use. Behave like GetMessage(), - * but also call message filters and optionally send WM_ENTERIDLE messages. - * 'hwnd' must be the handle of the dialog or menu window. - * 'code' is the message filter value (MSGF_??? codes). - */ -WINBOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner, - WPARAM code, WORD flags, WINBOOL sendIdle ) -{ - for (;;) - { - if (sendIdle) - { - if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE )) - { - /* No message present -> send ENTERIDLE and wait */ - if (IsWindow(hwndOwner)) - SendMessageW( hwndOwner, WM_ENTERIDLE, - code, (LPARAM)hwnd ); - MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE ); - } - } - else /* Always wait for a message */ - MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE ); - - /* Call message filters */ - - if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER )) - { - MSG *pmsg = HeapAlloc(GetProcessHeap(),0,sizeof(MSG)); - if (pmsg) - { - WINBOOL ret; - *pmsg = *msg; - ret = ((WINBOOL)HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0, - (LPARAM)(pmsg) ) || - (WINBOOL)HOOK_CallHooksA( WH_MSGFILTER, code, 0, - (LPARAM)(pmsg) )); - HeapFree(GetProcessHeap(),0,pmsg); - if (ret) - { - /* Message filtered -> remove it from the queue */ - /* if it's still there. */ - if (!(flags & PM_REMOVE)) - MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE ); - continue; - } - } - } - - return (msg->message != WM_QUIT); - } -} - -/************************************************************************ - * MSG_CallWndProcHook - */ -void MSG_CallWndProcHook( LPMSG pmsg, WINBOOL bUnicode ) -{ - CWPSTRUCT cwp; - - cwp.lParam = pmsg->lParam; - cwp.wParam = pmsg->wParam; - cwp.message = pmsg->message; - cwp.hwnd = pmsg->hwnd; - - if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp); - else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp ); - - pmsg->lParam = cwp.lParam; - pmsg->wParam = cwp.wParam; - pmsg->message = cwp.message; - pmsg->hwnd = cwp.hwnd; -} - -struct accent_char -{ - BYTE ac_accent; - BYTE ac_char; - BYTE ac_result; -}; - -static const struct accent_char accent_chars[] = -{ -/* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */ - {'`', 'A', '\300'}, {'`', 'a', '\340'}, - {'\'', 'A', '\301'}, {'\'', 'a', '\341'}, - {'^', 'A', '\302'}, {'^', 'a', '\342'}, - {'~', 'A', '\303'}, {'~', 'a', '\343'}, - {'"', 'A', '\304'}, {'"', 'a', '\344'}, - {'O', 'A', '\305'}, {'o', 'a', '\345'}, - {'0', 'A', '\305'}, {'0', 'a', '\345'}, - {'A', 'A', '\305'}, {'a', 'a', '\345'}, - {'A', 'E', '\306'}, {'a', 'e', '\346'}, - {',', 'C', '\307'}, {',', 'c', '\347'}, - {'`', 'E', '\310'}, {'`', 'e', '\350'}, - {'\'', 'E', '\311'}, {'\'', 'e', '\351'}, - {'^', 'E', '\312'}, {'^', 'e', '\352'}, - {'"', 'E', '\313'}, {'"', 'e', '\353'}, - {'`', 'I', '\314'}, {'`', 'i', '\354'}, - {'\'', 'I', '\315'}, {'\'', 'i', '\355'}, - {'^', 'I', '\316'}, {'^', 'i', '\356'}, - {'"', 'I', '\317'}, {'"', 'i', '\357'}, - {'-', 'D', '\320'}, {'-', 'd', '\360'}, - {'~', 'N', '\321'}, {'~', 'n', '\361'}, - {'`', 'O', '\322'}, {'`', 'o', '\362'}, - {'\'', 'O', '\323'}, {'\'', 'o', '\363'}, - {'^', 'O', '\324'}, {'^', 'o', '\364'}, - {'~', 'O', '\325'}, {'~', 'o', '\365'}, - {'"', 'O', '\326'}, {'"', 'o', '\366'}, - {'/', 'O', '\330'}, {'/', 'o', '\370'}, - {'`', 'U', '\331'}, {'`', 'u', '\371'}, - {'\'', 'U', '\332'}, {'\'', 'u', '\372'}, - {'^', 'U', '\333'}, {'^', 'u', '\373'}, - {'"', 'U', '\334'}, {'"', 'u', '\374'}, - {'\'', 'Y', '\335'}, {'\'', 'y', '\375'}, - {'T', 'H', '\336'}, {'t', 'h', '\376'}, - {'s', 's', '\337'}, {'"', 'y', '\377'}, - {'s', 'z', '\337'}, {'i', 'j', '\377'}, - /* iso-8859-2 uses this */ - {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */ - {'<', 'S', '\251'}, {'<', 's', '\271'}, - {'<', 'T', '\253'}, {'<', 't', '\273'}, - {'<', 'Z', '\256'}, {'<', 'z', '\276'}, - {'<', 'C', '\310'}, {'<', 'c', '\350'}, - {'<', 'E', '\314'}, {'<', 'e', '\354'}, - {'<', 'D', '\317'}, {'<', 'd', '\357'}, - {'<', 'N', '\322'}, {'<', 'n', '\362'}, - {'<', 'R', '\330'}, {'<', 'r', '\370'}, - {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */ - {';', 'E', '\312'}, {';', 'e', '\332'}, - {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */ - {'\'', 'R', '\300'}, {'\'', 'r', '\340'}, - {'\'', 'L', '\305'}, {'\'', 'l', '\345'}, - {'\'', 'C', '\306'}, {'\'', 'c', '\346'}, - {'\'', 'N', '\321'}, {'\'', 'n', '\361'}, -/* collision whith S, from iso-8859-9 !!! */ - {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */ - {',', 'T', '\336'}, {',', 't', '\376'}, - {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */ - {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */ - {'/', 'D', '\320'}, {'/', 'd', '\360'}, - {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */ - {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */ - {'\275', 'U', '\334'}, {'\275', 'u', '\374'}, - {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */ - /* iso-8859-3 uses this */ - {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */ - {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */ - {'>', 'J', '\254'}, {'>', 'j', '\274'}, - {'>', 'C', '\306'}, {'>', 'c', '\346'}, - {'>', 'G', '\330'}, {'>', 'g', '\370'}, - {'>', 'S', '\336'}, {'>', 's', '\376'}, -/* collision whith G( from iso-8859-9 !!! */ - {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */ - {'(', 'U', '\335'}, {'(', 'u', '\375'}, -/* collision whith I. from iso-8859-3 !!! */ - {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */ - {'.', 'C', '\305'}, {'.', 'c', '\345'}, - {'.', 'G', '\325'}, {'.', 'g', '\365'}, - /* iso-8859-4 uses this */ - {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */ - {',', 'L', '\246'}, {',', 'l', '\266'}, - {',', 'G', '\253'}, {',', 'g', '\273'}, - {',', 'N', '\321'}, {',', 'n', '\361'}, - {',', 'K', '\323'}, {',', 'k', '\363'}, - {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */ - {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */ - {'-', 'A', '\300'}, {'-', 'a', '\340'}, - {'-', 'I', '\317'}, {'-', 'i', '\357'}, - {'-', 'O', '\322'}, {'-', 'o', '\362'}, - {'-', 'U', '\336'}, {'-', 'u', '\376'}, - {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */ - {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */ - {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */ - {';', 'U', '\331'}, {';', 'u', '\371'}, - /* iso-8859-9 uses this */ - /* iso-8859-9 has really bad choosen G( S, and I. as they collide - * whith the same letters on other iso-8859-x (that is they are on - * different places :-( ), if you use turkish uncomment these and - * comment out the lines in iso-8859-2 and iso-8859-3 sections - * FIXME: should be dynamic according to chosen language - * if/when Wine has turkish support. - */ -/* collision whith G( from iso-8859-3 !!! */ -/* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */ -/* collision whith S, from iso-8859-2 !!! */ -/* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */ -/* collision whith I. from iso-8859-3 !!! */ -/* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */ -}; - - -/*********************************************************************** - * MSG_DoTranslateMessage - * - * Implementation of TranslateMessage. - * - * TranslateMessage translates virtual-key messages into character-messages, - * as follows : - * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. - * ditto replacing WM_* with WM_SYS* - * This produces WM_CHAR messages only for keys mapped to ASCII characters - * by the keyboard driver. - */ -WINBOOL MSG_DoTranslateMessage( UINT message, HWND hwnd, - WPARAM wParam, LPARAM lParam ) -{ - int dead_char = 0; - BYTE wp[2]; - - if (message != WM_MOUSEMOVE && message != WM_TIMER) - DPRINT( "(%s, %04X, %08lX)\n", - SPY_GetMsgName(message), wParam, lParam ); - if(message >= WM_KEYFIRST && message <= WM_KEYLAST) - DPRINT( "(%s, %04X, %08lX)\n", - SPY_GetMsgName(message), wParam, lParam ); - - if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE; - - DPRINT( "Translating key %04X, scancode %04X\n", - wParam, HIWORD(lParam) ); - - /* FIXME : should handle ToAscii yielding 2 */ - switch (ToAscii(wParam, HIWORD(lParam), - QueueKeyStateTable,(LPWORD)wp, 0)) - { - case 1 : - message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR; - /* Should dead chars handling go in ToAscii ? */ - if (dead_char) - { - int i; - - if (wp[0] == ' ') wp[0] = dead_char; - if (dead_char == 0xa2) dead_char = '('; - else if (dead_char == 0xa8) dead_char = '"'; - else if (dead_char == 0xb2) dead_char = ';'; - else if (dead_char == 0xb4) dead_char = '\''; - else if (dead_char == 0xb7) dead_char = '<'; - else if (dead_char == 0xb8) dead_char = ','; - else if (dead_char == 0xff) dead_char = '.'; - for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++) - if ((accent_chars[i].ac_accent == dead_char) && - (accent_chars[i].ac_char == wp[0])) - { - wp[0] = accent_chars[i].ac_result; - break; - } - dead_char = 0; - } - DPRINT( "1 -> PostMessage(%s)\n", SPY_GetMsgName(message)); - PostMessageA( hwnd, message, wp[0], lParam ); - return TRUE; - - case -1 : - message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR; - dead_char = wp[0]; - DPRINT( "-1 -> PostMessage(%s)\n", - SPY_GetMsgName(message)); - PostMessageA( hwnd, message, wp[0], lParam ); - return TRUE; - } - return FALSE; -} - - -LRESULT MSG_SendMessage( WND *wndPtr, UINT msg, WPARAM wParam, LPARAM lParam ) -{ - - LRESULT ret; - - if ( wndPtr == NULL ) - return 0; - - // if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ)) - // return 0; /* Don't send anything if the task is dying */ - - - - if ( wndPtr->class->bUnicode ) - ret = CallWindowProcW( (WNDPROC)wndPtr->winproc, - wndPtr->hwndSelf, msg, wParam, lParam ); - else - ret = CallWindowProcA( (WNDPROC)wndPtr->winproc, - wndPtr->hwndSelf, msg, wParam, lParam ); - - return ret; -} - -HTASK GetCurrentTask(void) -{ - return (HTASK)-2; -} - -//FIXME -int init = 0; -MESSAGEQUEUE Queue; -HQUEUE hThreadQ = &Queue;; - -HQUEUE GetThreadQueue( DWORD thread ) -{ - if ( init == 0 ) { - init = 1; - HEAP_memset(&Queue,0,sizeof(MESSAGEQUEUE)); - } - return hThreadQ; -} - - - -HQUEUE SetThreadQueue( DWORD thread, HQUEUE hQueue ) -{ - HQUEUE oldQueue = hThreadQ; - hThreadQ = hQueue; - return oldQueue; -} - -HANDLE GetFastQueue( void ) -{ - return hThreadQ; -} - -int UserYield(void) -{ - return SuspendThread(GetCurrentThread()); -} diff --git a/reactos/lib/user32/internal/nc.c b/reactos/lib/user32/internal/nc.c deleted file mode 100644 index c5e359df20b..00000000000 --- a/reactos/lib/user32/internal/nc.c +++ /dev/null @@ -1,2320 +0,0 @@ -#include -#define MAX max -#define MIN min - -#include -#include -#include -#include -#include -#include - -// GetBitmapDimensionEx in NC_DrawMaxButton95 returns TRUE on invalid bitmap - -static HBITMAP hbitmapClose = 0; -static HBITMAP hbitmapCloseD = 0; -static HBITMAP hbitmapMinimize = 0; -static HBITMAP hbitmapMinimizeD = 0; -static HBITMAP hbitmapMaximize = 0; -static HBITMAP hbitmapMaximizeD = 0; -static HBITMAP hbitmapRestore = 0; -static HBITMAP hbitmapRestoreD = 0; - -#define SC_ABOUTWINE (SC_SCREENSAVE+1) -#define SC_PUTMARK (SC_SCREENSAVE+2) - - /* Some useful macros */ -#define HAS_DLGFRAME(style,exStyle) \ - (((exStyle) & WS_EX_DLGMODALFRAME) || \ - (((style) & WS_DLGFRAME) && !((style) & WS_BORDER))) - -#define HAS_THICKFRAME(style) \ - (((style) & WS_THICKFRAME) && \ - !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME)) - - -#define HAS_THINFRAME(style) \ - (((style) & WS_BORDER) || !((style) & (WS_CHILD | WS_POPUP))) - - -#define HAS_FIXEDFRAME(style,exStyle) \ - (((((exStyle) & WS_EX_DLGMODALFRAME) || \ - ((style) & WS_DLGFRAME)) && ((style) & WS_BORDER)) && \ - !((style) & WS_THICKFRAME)) - -#define HAS_SIZEFRAME(style) \ - (((style) & WS_THICKFRAME) && \ - !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME)) - -#define HAS_MENU(w) (!((w)->dwStyle & WS_CHILD) && ((w)->wIDmenu != 0)) - -#define ON_LEFT_BORDER(hit) \ - (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT)) -#define ON_RIGHT_BORDER(hit) \ - (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT)) -#define ON_TOP_BORDER(hit) \ - (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT)) -#define ON_BOTTOM_BORDER(hit) \ - (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT)) - - -int TWEAK_WineLook = WIN95_LOOK; - - -/*********************************************************************** - * WIN_WindowNeedsWMBorder - * - * This method defines the rules for a window to have a WM border, - * caption... It is used for consitency purposes. - */ -BOOL WIN_WindowNeedsWMBorder( DWORD style, DWORD exStyle ) -{ - if (!(style & WS_CHILD) && - !(exStyle & WS_EX_TOOLWINDOW) && - ( ((style & WS_CAPTION) == WS_CAPTION) || - (style & WS_THICKFRAME))) - return TRUE; - //if (exStyle & WS_EX_TRAYWINDOW) - //return TRUE; - return FALSE; -} - -/*********************************************************************** - * NC_AdjustRect - * - * Compute the size of the window rectangle from the size of the - * client rectangle. - */ -void NC_AdjustRect( LPRECT rect, DWORD style, WINBOOL menu, - DWORD exStyle ) -{ - - if(style & WS_ICONIC) return; - /* Decide if the window will be managed (see CreateWindowEx) */ - // removed Options.managed && - if (!( !(style & WS_CHILD) && - ((style & (WS_DLGFRAME | WS_THICKFRAME)) || - (exStyle & WS_EX_DLGMODALFRAME)))) - { - if (HAS_DLGFRAME( style, exStyle )) - InflateRect(rect, SYSMETRICS_CXDLGFRAME, SYSMETRICS_CYDLGFRAME ); - else - { - if (HAS_THICKFRAME(style)) - InflateRect( rect, SYSMETRICS_CXFRAME, SYSMETRICS_CYFRAME ); - if (style & WS_BORDER) - InflateRect( rect, SYSMETRICS_CXBORDER, SYSMETRICS_CYBORDER); - } - - if ((style & WS_CAPTION) == WS_CAPTION) - rect->top -= SYSMETRICS_CYCAPTION - SYSMETRICS_CYBORDER; - } - if (menu) rect->top -= SYSMETRICS_CYMENU + SYSMETRICS_CYBORDER; - - if (style & WS_VSCROLL) { - rect->right += SYSMETRICS_CXVSCROLL - 1; - if(!(style & WS_BORDER)) - rect->right++; - } - - if (style & WS_HSCROLL) { - rect->bottom += SYSMETRICS_CYHSCROLL - 1; - if(!(style & WS_BORDER)) - rect->bottom++; - } -} - -/****************************************************************************** - * NC_AdjustRectOuter95 - * - * Computes the size of the "outside" parts of the window based on the - * parameters of the client area. - * - + PARAMS - * LPRECT rect - * DWORD style - * WINBOOL menu - * DWORD exStyle - * - * NOTES - * "Outer" parts of a window means the whole window frame, caption and - * menu bar. It does not include "inner" parts of the frame like client - * edge, static edge or scroll bars. - * - * Revision history - * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original (NC_AdjustRect95) cut & paste from NC_AdjustRect - * - * 20-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Split NC_AdjustRect95 into NC_AdjustRectOuter95 and - * NC_AdjustRectInner95 and added handling of Win95 styles. - * - *****************************************************************************/ - - -void -NC_AdjustRectOuter95 (LPRECT rect, DWORD style, BOOL menu, DWORD exStyle) -{ - if(style & WS_ICONIC) return; - - /* Decide if the window will be managed (see CreateWindowEx) */ - if (!WIN_WindowNeedsWMBorder(style, exStyle)) - { - if (HAS_THICKFRAME( style )) - InflateRect( rect, GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME) ); - else - if (HAS_DLGFRAME( style, exStyle )) - InflateRect(rect, GetSystemMetrics(SM_CXDLGFRAME), GetSystemMetrics(SM_CYDLGFRAME) ); - else - if (HAS_THINFRAME( style )) - InflateRect( rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER)); - - if ((style & WS_CAPTION) == WS_CAPTION) - { - if (exStyle & WS_EX_TOOLWINDOW) - rect->top -= GetSystemMetrics(SM_CYSMCAPTION); - else - rect->top -= GetSystemMetrics(SM_CYCAPTION); - } - } - - if (menu) - rect->top -= GetSystemMetrics(SM_CYMENU); -} - - -/****************************************************************************** - * NC_AdjustRectInner95 - * - * Computes the size of the "inside" part of the window based on the - * parameters of the client area. - * - + PARAMS - * LPRECT16 rect - * DWORD style - * DWORD exStyle - * - * NOTES - * "Inner" part of a window means the window frame inside of the flat - * window frame. It includes the client edge, the static edge and the - * scroll bars. - * - * Revision history - * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original (NC_AdjustRect95) cut & paste from NC_AdjustRect - * - * 20-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Split NC_AdjustRect95 into NC_AdjustRectOuter95 and - * NC_AdjustRectInner95 and added handling of Win95 styles. - * - *****************************************************************************/ - -void -NC_AdjustRectInner95 (LPRECT rect, DWORD style, DWORD exStyle) -{ - if(style & WS_ICONIC) return; - - if (exStyle & WS_EX_CLIENTEDGE) - InflateRect (rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)); - - if (exStyle & WS_EX_STATICEDGE) - InflateRect (rect, GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER)); - - if (style & WS_VSCROLL) rect->right += GetSystemMetrics(SM_CXVSCROLL); - if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL); -} - -/*********************************************************************** - * NC_HandleNCCalcSize - * - * Handle a WM_NCCALCSIZE message. Called from DefWindowProc(). - */ -LONG NC_HandleNCCalcSize( WND *pWnd, RECT *winRect ) -{ - RECT tmpRect = { 0, 0, 0, 0 }; - LONG result = 0; - - if (pWnd->class->style & CS_VREDRAW) result |= WVR_VREDRAW; - if (pWnd->class->style & CS_HREDRAW) result |= WVR_HREDRAW; - - if( !( pWnd->dwStyle & WS_MINIMIZE ) ) { - if (TWEAK_WineLook == WIN31_LOOK) - NC_AdjustRect( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle ); - else - NC_AdjustRectOuter95( &tmpRect, pWnd->dwStyle, FALSE, pWnd->dwExStyle ); - - winRect->left -= tmpRect.left; - winRect->top -= tmpRect.top; - winRect->right -= tmpRect.right; - winRect->bottom -= tmpRect.bottom; - - if (HAS_MENU(pWnd)) { - DPRINT( "Calling GetMenuBarHeight with HWND 0x%x, width %d, at (%d, %d).\n", pWnd->hwndSelf, - winRect->right - winRect->left, -tmpRect.left, -tmpRect.top ); - - winRect->top += - MENU_GetMenuBarHeight( pWnd->hwndSelf, - winRect->right - winRect->left, - -tmpRect.left, -tmpRect.top ) + 1; - } - - if (TWEAK_WineLook > WIN31_LOOK) { - SetRect (&tmpRect, 0, 0, 0, 0); - NC_AdjustRectInner95 (&tmpRect, pWnd->dwStyle, pWnd->dwExStyle); - winRect->left -= tmpRect.left; - winRect->top -= tmpRect.top; - winRect->right -= tmpRect.right; - winRect->bottom -= tmpRect.bottom; - } - } - return result; -} - - -/*********************************************************************** - * NC_GetInsideRect - * - * Get the 'inside' rectangle of a window, i.e. the whole window rectangle - * but without the borders (if any). - * The rectangle is in window coordinates (for drawing with GetWindowDC()). - */ -static void NC_GetInsideRect( HWND hwnd, RECT *rect ) -{ - WND * wndPtr = WIN_FindWndPtr( hwnd ); - - rect->top = rect->left = 0; - rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left; - rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top; -// || (wndPtr->flags & WIN_MANAGED) - if ((wndPtr->dwStyle & WS_ICONIC) ) return; - - /* Remove frame from rectangle */ - if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle )) - { - InflateRect( rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME); - if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) - InflateRect( rect, -1, 0 ); - } - else - { - if (HAS_THICKFRAME( wndPtr->dwStyle )) - InflateRect( rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME ); - if (wndPtr->dwStyle & WS_BORDER) - InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER ); - } - - return; -} - - -/*********************************************************************** - * NC_GetInsideRect95 - * - * Get the 'inside' rectangle of a window, i.e. the whole window rectangle - * but without the borders (if any). - * The rectangle is in window coordinates (for drawing with GetWindowDC()). - */ - -static void -NC_GetInsideRect95 (HWND hwnd, RECT *rect) -{ - WND * wndPtr = WIN_FindWndPtr( hwnd ); - - rect->top = rect->left = 0; - rect->right = wndPtr->rectWindow.right - wndPtr->rectWindow.left; - rect->bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top; - -// || (wndPtr->flags & WIN_MANAGED) - if ((wndPtr->dwStyle & WS_ICONIC) ) return; - - /* Remove frame from rectangle */ - if (HAS_FIXEDFRAME (wndPtr->dwStyle, wndPtr->dwExStyle )) - { - InflateRect( rect, -SYSMETRICS_CXFIXEDFRAME, -SYSMETRICS_CYFIXEDFRAME); - } - else if (HAS_SIZEFRAME (wndPtr->dwStyle)) - { - InflateRect( rect, -SYSMETRICS_CXSIZEFRAME, -SYSMETRICS_CYSIZEFRAME ); - -/* if (wndPtr->dwStyle & WS_BORDER) - InflateRect( rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER );*/ - } - -// if (wndPtr->dwStyle & WS_CHILD) { - if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE) - InflateRect(rect, -SYSMETRICS_CXEDGE, -SYSMETRICS_CYEDGE); - - if (wndPtr->dwExStyle & WS_EX_STATICEDGE) - InflateRect(rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER); - // } - - return; -} - - -/*********************************************************************** - * NC_DoNCHitTest - * - * Handle a WM_NCHITTEST message. Called from NC_HandleNcHitTest(). - */ - -LONG NC_DoNCHitTest (WND *wndPtr, POINT pt ) -{ - RECT rect; - - DPRINT( "hwnd=%04x pt=%d,%d\n", - wndPtr->hwndSelf, pt.x, pt.y ); - - GetWindowRect (wndPtr->hwndSelf, &rect ); - if (!PtInRect( &rect, pt )) return HTNOWHERE; - - if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION; - -// if (!(wndPtr->flags & WIN_MANAGED)) - { - /* Check borders */ - if (HAS_THICKFRAME( wndPtr->dwStyle )) - { - InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME ); - if (wndPtr->dwStyle & WS_BORDER) - InflateRect(&rect,-SYSMETRICS_CXBORDER,-SYSMETRICS_CYBORDER); - if (!PtInRect( &rect, pt )) - { - /* Check top sizing border */ - if (pt.y < rect.top) - { - if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT; - if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT; - return HTTOP; - } - /* Check bottom sizing border */ - if (pt.y >= rect.bottom) - { - if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT; - if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT; - return HTBOTTOM; - } - /* Check left sizing border */ - if (pt.x < rect.left) - { - if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT; - if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT; - return HTLEFT; - } - /* Check right sizing border */ - if (pt.x >= rect.right) - { - if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT; - if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT; - return HTRIGHT; - } - } - } - else /* No thick frame */ - { - if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle )) - InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME); - else if (wndPtr->dwStyle & WS_BORDER) - InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER); - if (!PtInRect( &rect, pt )) return HTBORDER; - } - - /* Check caption */ - - if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION) - { - rect.top += sysMetrics[SM_CYCAPTION] - 1; - if (!PtInRect( &rect, pt )) - { - /* Check system menu */ - if (wndPtr->dwStyle & WS_SYSMENU) - rect.left += SYSMETRICS_CXSIZE; - if (pt.x <= rect.left) return HTSYSMENU; - /* Check maximize box */ - if (wndPtr->dwStyle & WS_MAXIMIZEBOX) - rect.right -= SYSMETRICS_CXSIZE + 1; - if (pt.x >= rect.right) return HTMAXBUTTON; - /* Check minimize box */ - if (wndPtr->dwStyle & WS_MINIMIZEBOX) - rect.right -= SYSMETRICS_CXSIZE + 1; - if (pt.x >= rect.right) return HTMINBUTTON; - return HTCAPTION; - } - } - } - - /* Check client area */ - - ScreenToClient( wndPtr->hwndSelf, &pt ); - GetClientRect( wndPtr->hwndSelf, &rect ); - if (PtInRect( &rect, pt )) return HTCLIENT; - - /* Check vertical scroll bar */ - - if (wndPtr->dwStyle & WS_VSCROLL) - { - rect.right += SYSMETRICS_CXVSCROLL; - if (PtInRect( &rect, pt )) return HTVSCROLL; - } - - /* Check horizontal scroll bar */ - - if (wndPtr->dwStyle & WS_HSCROLL) - { - rect.bottom += SYSMETRICS_CYHSCROLL; - if (PtInRect( &rect, pt )) - { - /* Check size box */ - if ((wndPtr->dwStyle & WS_VSCROLL) && - (pt.x >= rect.right - SYSMETRICS_CXVSCROLL)) - return HTSIZE; - return HTHSCROLL; - } - } - - /* Check menu bar */ - - if (HAS_MENU(wndPtr)) - { - if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right)) - return HTMENU; - } - - /* Should never get here */ - return HTERROR; -} - - -/*********************************************************************** - * NC_DoNCHitTest95 - * - * Handle a WM_NCHITTEST message. Called from NC_HandleNCHitTest(). - * - * FIXME: Just a modified copy of the Win 3.1 version. - */ - -LONG -NC_DoNCHitTest95 (WND *wndPtr, POINT pt ) -{ - RECT rect; - - DPRINT( "hwnd=%04x pt=%d,%d\n", - wndPtr->hwndSelf, pt.x, pt.y ); - - GetWindowRect (wndPtr->hwndSelf, &rect ); - if (!PtInRect( &rect, pt )) return HTNOWHERE; - - if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION; - -// if (!(wndPtr->flags & WIN_MANAGED)) - { - /* Check borders */ - if (HAS_SIZEFRAME( wndPtr->dwStyle )) - { - InflateRect( &rect, -SYSMETRICS_CXFRAME, -SYSMETRICS_CYFRAME ); -/* if (wndPtr->dwStyle & WS_BORDER) */ -/* InflateRect(&rect,-SYSMETRICS_CXBORDER,-SYSMETRICS_CYBORDER); */ - if (!PtInRect( &rect, pt )) - { - /* Check top sizing border */ - if (pt.y < rect.top) - { - if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTTOPLEFT; - if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTTOPRIGHT; - return HTTOP; - } - /* Check bottom sizing border */ - if (pt.y >= rect.bottom) - { - if (pt.x < rect.left+SYSMETRICS_CXSIZE) return HTBOTTOMLEFT; - if (pt.x >= rect.right-SYSMETRICS_CXSIZE) return HTBOTTOMRIGHT; - return HTBOTTOM; - } - /* Check left sizing border */ - if (pt.x < rect.left) - { - if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPLEFT; - if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMLEFT; - return HTLEFT; - } - /* Check right sizing border */ - if (pt.x >= rect.right) - { - if (pt.y < rect.top+SYSMETRICS_CYSIZE) return HTTOPRIGHT; - if (pt.y >= rect.bottom-SYSMETRICS_CYSIZE) return HTBOTTOMRIGHT; - return HTRIGHT; - } - } - } - else /* No thick frame */ - { - if (HAS_FIXEDFRAME( wndPtr->dwStyle, wndPtr->dwExStyle )) - InflateRect(&rect, -SYSMETRICS_CXDLGFRAME, -SYSMETRICS_CYDLGFRAME); -/* else if (wndPtr->dwStyle & WS_BORDER) */ -/* InflateRect(&rect, -SYSMETRICS_CXBORDER, -SYSMETRICS_CYBORDER); */ - if (!PtInRect( &rect, pt )) return HTBORDER; - } - - /* Check caption */ - - if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION) - { - if (wndPtr->dwExStyle & WS_EX_TOOLWINDOW) - rect.top += sysMetrics[SM_CYSMCAPTION] - 1; - else - rect.top += sysMetrics[SM_CYCAPTION] - 1; - if (!PtInRect( &rect, pt )) - { - /* Check system menu */ - if ((wndPtr->dwStyle & WS_SYSMENU) && - ((wndPtr->class->hIconSm) || (wndPtr->class->hIcon))) - rect.left += sysMetrics[SM_CYCAPTION] - 1; - if (pt.x < rect.left) return HTSYSMENU; - - /* Check close button */ - if (wndPtr->dwStyle & WS_SYSMENU) - rect.right -= sysMetrics[SM_CYCAPTION] - 1; - if (pt.x > rect.right) return HTCLOSE; - - /* Check maximize box */ - if (wndPtr->dwStyle & WS_MAXIMIZEBOX) - rect.right -= SYSMETRICS_CXSIZE + 1; - if (pt.x > rect.right) return HTMAXBUTTON; - - /* Check minimize box */ - if (wndPtr->dwStyle & WS_MINIMIZEBOX) - rect.right -= SYSMETRICS_CXSIZE + 1; - if (pt.x > rect.right) return HTMINBUTTON; - return HTCAPTION; - } - } - } - - /* Check client area */ - - ScreenToClient( wndPtr->hwndSelf, &pt ); - GetClientRect( wndPtr->hwndSelf, &rect ); - if (PtInRect( &rect, pt )) return HTCLIENT; - - /* Check vertical scroll bar */ - - if (wndPtr->dwStyle & WS_VSCROLL) - { - rect.right += SYSMETRICS_CXVSCROLL; - if (PtInRect( &rect, pt )) return HTVSCROLL; - } - - /* Check horizontal scroll bar */ - - if (wndPtr->dwStyle & WS_HSCROLL) - { - rect.bottom += SYSMETRICS_CYHSCROLL; - if (PtInRect( &rect, pt )) - { - /* Check size box */ - if ((wndPtr->dwStyle & WS_VSCROLL) && - (pt.x >= rect.right - SYSMETRICS_CXVSCROLL)) - return HTSIZE; - return HTHSCROLL; - } - } - - /* Check menu bar */ - - if (HAS_MENU(wndPtr)) - { - if ((pt.y < 0) && (pt.x >= 0) && (pt.x < rect.right)) - return HTMENU; - } - - /* Should never get here */ - return HTERROR; -} - - -/*********************************************************************** - * NC_HandleNCHitTest - * - * Handle a WM_NCHITTEST message. Called from DefWindowProc(). - */ -LONG -NC_HandleNCHitTest (HWND hwnd , POINT pt) -{ - WND *wndPtr = WIN_FindWndPtr (hwnd); - - if (!wndPtr) - return HTERROR; - - if (TWEAK_WineLook == WIN31_LOOK) - return NC_DoNCHitTest (wndPtr, pt); - else - return NC_DoNCHitTest95 (wndPtr, pt); -} - - -/*********************************************************************** - * NC_DrawSysButton - */ -void NC_DrawSysButton( HWND hwnd, HDC hdc, WINBOOL down ) -{ - RECT rect; - HDC hdcMem; - HBITMAP hbitmap; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - -// if( !(wndPtr->flags & WIN_MANAGED) ) - { - NC_GetInsideRect( hwnd, &rect ); - hdcMem = CreateCompatibleDC( hdc ); - hbitmap = SelectObject( hdcMem, hbitmapClose ); - BitBlt(hdc, rect.left, rect.top, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE, - hdcMem, (wndPtr->dwStyle & WS_CHILD) ? SYSMETRICS_CXSIZE : 0, 0, - down ? NOTSRCCOPY : SRCCOPY ); - SelectObject( hdcMem, hbitmap ); - DeleteDC( hdcMem ); - } -} - - -/*********************************************************************** - * NC_DrawMaxButton - */ -static void NC_DrawMaxButton( HWND hwnd, HDC hdc, WINBOOL down ) -{ - RECT rect; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - HDC hdcMem; - -// if( !(wndPtr->flags & WIN_MANAGED) ) - { - NC_GetInsideRect( hwnd, &rect ); - hdcMem = CreateCompatibleDC( hdc ); - SelectObject( hdcMem, (IsZoomed(hwnd) - ? (down ? hbitmapRestoreD : hbitmapRestore) - : (down ? hbitmapMaximizeD : hbitmapMaximize)) ); - BitBlt( hdc, rect.right - SYSMETRICS_CXSIZE - 1, rect.top, - SYSMETRICS_CXSIZE + 1, SYSMETRICS_CYSIZE, hdcMem, 0, 0, - SRCCOPY ); - DeleteDC( hdcMem ); - } -} - - -/*********************************************************************** - * NC_DrawMinButton - */ -static void NC_DrawMinButton( HWND hwnd, HDC hdc, WINBOOL down ) -{ - RECT rect; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - HDC hdcMem; - -// if( !(wndPtr->flags & WIN_MANAGED) ) - { - NC_GetInsideRect( hwnd, &rect ); - hdcMem = CreateCompatibleDC( hdc ); - SelectObject( hdcMem, (down ? hbitmapMinimizeD : hbitmapMinimize) ); - if (wndPtr->dwStyle & WS_MAXIMIZEBOX) rect.right -= SYSMETRICS_CXSIZE+1; - BitBlt( hdc, rect.right - SYSMETRICS_CXSIZE - 1, rect.top, - SYSMETRICS_CXSIZE + 1, SYSMETRICS_CYSIZE, hdcMem, 0, 0, - SRCCOPY ); - DeleteDC( hdcMem ); - } -} - - -/****************************************************************************** - * - * void NC_DrawSysButton95( - * HWND hwnd, - * HDC hdc, - * WINBOOL down ) - * - * Draws the Win95 system icon. - * - * Revision history - * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original implementation from NC_DrawSysButton source. - * 11-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Fixed most bugs. - * - *****************************************************************************/ - -WINBOOL -NC_DrawSysButton95 (HWND hwnd, HDC hdc, WINBOOL down) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - -// if( !(wndPtr->flags & WIN_MANAGED) ) - { - HICON hIcon = 0; - RECT rect; - - NC_GetInsideRect95( hwnd, &rect ); - - if (wndPtr->class->hIconSm) - hIcon = wndPtr->class->hIconSm; - else if (wndPtr->class->hIcon) - hIcon = wndPtr->class->hIcon; - - if (hIcon) - DrawIconEx(hdc, rect.left + 2, rect.top + 2, hIcon, - sysMetrics[SM_CXSMICON], - sysMetrics[SM_CYSMICON], - 0, 0, DI_NORMAL); - - return (hIcon != 0); - } - return FALSE; -} - - -/****************************************************************************** - * - * void NC_DrawCloseButton95( - * HWND hwnd, - * HDC hdc, - * WINBOOL down ) - * - * Draws the Win95 close button. - * - * Revision history - * 11-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Original implementation from NC_DrawSysButton95 source. - * - *****************************************************************************/ - -void -NC_DrawCloseButton95 (HWND hwnd, HDC hdc, WINBOOL down) -{ - RECT rect; - HDC hdcMem; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - -// if( !(wndPtr->flags & WIN_MANAGED) ) - { - BITMAP bmp; - HBITMAP hBmp, hOldBmp; - - NC_GetInsideRect95( hwnd, &rect ); - - hdcMem = CreateCompatibleDC( hdc ); - hBmp = /*down ? hbitmapCloseD :*/ hbitmapClose; - hOldBmp = SelectObject (hdcMem, hBmp); - GetObject(hBmp, sizeof(BITMAP), &bmp); - BitBlt(hdc, rect.right - (sysMetrics[SM_CYCAPTION] + 1 + bmp.bmWidth) / 2, - rect.top + (sysMetrics[SM_CYCAPTION] - 1 - bmp.bmHeight) / 2, - bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, down ? NOTSRCCOPY : SRCCOPY); - - SelectObject(hdcMem, hOldBmp); - DeleteDC (hdcMem); - } -} - - -/****************************************************************************** - * - * NC_DrawMaxButton95( - * HWND hwnd, - * HDC hdc, - * WINBOOL down ) - * - * Draws the maximize button for Win95 style windows. - * - * Bugs - * Many. Spacing might still be incorrect. Need to fit a close - * button between the max button and the edge. - * Should scale the image with the title bar. And more... - * - * Revision history - * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original implementation. - * - *****************************************************************************/ - -static void NC_DrawMaxButton95( - HWND hwnd, - HDC hdc, - WINBOOL down ) -{ - RECT rect; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - SIZE bmsz; - HBITMAP bm; - BITMAP bmp; - HDC hdcMem; - - -// if( !(wndPtr->flags & WIN_MANAGED) ) - { - GetBitmapDimensionEx((bm = IsZoomed(hwnd) ? - (down ? hbitmapRestoreD : hbitmapRestore ) : - (down ? hbitmapMaximizeD : hbitmapMaximize)), - &bmsz); - - if ( bmsz.cx == 0 || bmsz.cy == 0 ) { - GetObject(bm, sizeof(BITMAP), &bmp); - bmsz.cx = bmp.bmWidth; - bmsz.cy = bmp.bmHeight; - DPRINT("WARN GetBitmapDimensionEx returned 0 size "); - } - - NC_GetInsideRect95( hwnd, &rect ); - - if (wndPtr->dwStyle & WS_SYSMENU) - rect.right -= sysMetrics[SM_CYCAPTION] + 1; - - hdcMem = CreateCompatibleDC( hdc ); - SelectObject( hdc, bm ); - BitBlt( hdc, rect.right - (sysMetrics[SM_CXSIZE] + bmsz.cx) / 2, - rect.top + (sysMetrics[SM_CYCAPTION] - 1 - bmsz.cy) / 2, - bmsz.cx, bmsz.cy, hdcMem, 0, 0, SRCCOPY ); - DeleteDC( hdcMem ); - } - - return; -} - - -/****************************************************************************** - * - * NC_DrawMinButton95( - * HWND hwnd, - * HDC hdc, - * WINBOOL down ) - * - * Draws the minimize button for Win95 style windows. - * - * Bugs - * Many. Spacing is still incorrect. Should scale the image with the - * title bar. And more... - * - * Revision history - * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original implementation. - * - *****************************************************************************/ - -static void NC_DrawMinButton95( - HWND hwnd, - HDC hdc, - WINBOOL down ) -{ - RECT rect; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - SIZE bmsz; - HBITMAP bm; - HDC hdcMem; -// !(wndPtr->flags & WIN_MANAGED) && - if( GetBitmapDimensionEx((bm = down ? hbitmapMinimizeD : - hbitmapMinimize), &bmsz)) { - - NC_GetInsideRect95( hwnd, &rect ); - - if (wndPtr->dwStyle & WS_SYSMENU) - rect.right -= sysMetrics[SM_CYCAPTION] + 1; - - if (wndPtr->dwStyle & WS_MAXIMIZEBOX) - rect.right += -1 - - (sysMetrics[SM_CXSIZE] + bmsz.cx) / 2; - - hdcMem = CreateCompatibleDC( hdc ); - SelectObject( hdc, bm ); - BitBlt( hdc, rect.right - (sysMetrics[SM_CXSIZE] + bmsz.cx) / 2, - rect.top + (sysMetrics[SM_CYCAPTION] - 1 - bmsz.cy) / 2, - bmsz.cx, bmsz.cy, hdcMem, 0, 0, SRCCOPY ); - DeleteDC( hdcMem ); - } - - return; -} - - -/*********************************************************************** - * NC_DrawFrame - * - * Draw a window frame inside the given rectangle, and update the rectangle. - * The correct pen for the frame must be selected in the DC. - */ -static void NC_DrawFrame( HDC hdc, RECT *rect, WINBOOL dlgFrame, - WINBOOL active ) -{ - INT width, height; - - // if (TWEAK_WineLook != WIN31_LOOK) -// DPRINT( "Called in Win95 mode. Aiee! Please report this.\n" ); - - if (dlgFrame) - { - width = SYSMETRICS_CXDLGFRAME - 1; - height = SYSMETRICS_CYDLGFRAME - 1; - SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : - COLOR_INACTIVECAPTION) ); - } - else - { - width = SYSMETRICS_CXFRAME - 1; - height = SYSMETRICS_CYFRAME - 1; - SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER : - COLOR_INACTIVEBORDER) ); - } - - /* Draw frame */ - PatBlt( hdc, rect->left, rect->top, - rect->right - rect->left, height, PATCOPY ); - PatBlt( hdc, rect->left, rect->top, - width, rect->bottom - rect->top, PATCOPY ); - PatBlt( hdc, rect->left, rect->bottom, - rect->right - rect->left, -height, PATCOPY ); - PatBlt( hdc, rect->right, rect->top, - -width, rect->bottom - rect->top, PATCOPY ); - - if (dlgFrame) - { - InflateRect( rect, -width, -height ); - } - else - { - INT decYOff = SYSMETRICS_CXFRAME + SYSMETRICS_CXSIZE; - INT decXOff = SYSMETRICS_CYFRAME + SYSMETRICS_CYSIZE; - - /* Draw inner rectangle */ - - SelectObject( hdc, GetStockObject(NULL_BRUSH) ); - Rectangle( hdc, rect->left + width, rect->top + height, - rect->right - width , rect->bottom - height ); - - /* Draw the decorations */ - - MoveToEx( hdc, rect->left, rect->top + decYOff, NULL ); - LineTo( hdc, rect->left + width, rect->top + decYOff ); - MoveToEx( hdc, rect->right - 1, rect->top + decYOff, NULL ); - LineTo( hdc, rect->right - width - 1, rect->top + decYOff ); - MoveToEx( hdc, rect->left, rect->bottom - decYOff, NULL ); - LineTo( hdc, rect->left + width, rect->bottom - decYOff ); - MoveToEx( hdc, rect->right - 1, rect->bottom - decYOff, NULL ); - LineTo( hdc, rect->right - width - 1, rect->bottom - decYOff ); - - MoveToEx( hdc, rect->left + decXOff, rect->top, NULL ); - LineTo( hdc, rect->left + decXOff, rect->top + height); - MoveToEx( hdc, rect->left + decXOff, rect->bottom - 1, NULL ); - LineTo( hdc, rect->left + decXOff, rect->bottom - height - 1 ); - MoveToEx( hdc, rect->right - decXOff, rect->top, NULL ); - LineTo( hdc, rect->right - decXOff, rect->top + height ); - MoveToEx( hdc, rect->right - decXOff, rect->bottom - 1, NULL ); - LineTo( hdc, rect->right - decXOff, rect->bottom - height - 1 ); - - InflateRect( rect, -width - 1, -height - 1 ); - } -} - - -/****************************************************************************** - * - * void NC_DrawFrame95( - * HDC hdc, - * RECT *rect, - * WINBOOL dlgFrame, - * WINBOOL active ) - * - * Draw a window frame inside the given rectangle, and update the rectangle. - * The correct pen for the frame must be selected in the DC. - * - * Bugs - * Many. First, just what IS a frame in Win95? Note that the 3D look - * on the outer edge is handled by NC_DoNCPaint95. As is the inner - * edge. The inner rectangle just inside the frame is handled by the - * Caption code. - * - * In short, for most people, this function should be a nop (unless - * you LIKE thick borders in Win95/NT4.0 -- I've been working with - * them lately, but just to get this code right). Even so, it doesn't - * appear to be so. It's being worked on... - * - * Revision history - * 06-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original implementation (based on NC_DrawFrame) - * 02-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Some minor fixes. - * - *****************************************************************************/ - -static void NC_DrawFrame95( - HDC hdc, - RECT *rect, - WINBOOL dlgFrame, - WINBOOL active ) -{ - INT width, height; - - if (dlgFrame) - { - width = sysMetrics[SM_CXDLGFRAME] - sysMetrics[SM_CXEDGE]; - height = sysMetrics[SM_CYDLGFRAME] - sysMetrics[SM_CYEDGE]; - } - else - { - width = sysMetrics[SM_CXFRAME] - sysMetrics[SM_CXEDGE]; - height = sysMetrics[SM_CYFRAME] - sysMetrics[SM_CYEDGE]; - } - - SelectObject( hdc, GetSysColorBrush(active ? COLOR_ACTIVEBORDER : - COLOR_INACTIVEBORDER) ); - - /* Draw frame */ - PatBlt( hdc, rect->left, rect->top, - rect->right - rect->left, height, PATCOPY ); - PatBlt( hdc, rect->left, rect->top, - width, rect->bottom - rect->top, PATCOPY ); - PatBlt( hdc, rect->left, rect->bottom, - rect->right - rect->left, -height, PATCOPY ); - PatBlt( hdc, rect->right, rect->top, - -width, rect->bottom - rect->top, PATCOPY ); - - InflateRect( rect, -width, -height ); -} - - - -/*********************************************************************** - * NC_DrawMovingFrame - * - * Draw the frame used when moving or resizing window. - * - * FIXME: This causes problems in Win95 mode. (why?) - */ -static void NC_DrawMovingFrame( HDC hdc, RECT *rect, WINBOOL thickframe ) -{ - if (thickframe) - { - FastWindowFrame( hdc, rect, SYSMETRICS_CXFRAME, - SYSMETRICS_CYFRAME, PATINVERT ); - } - else DrawFocusRect( hdc, rect ); -} - - -/*********************************************************************** - * NC_DrawCaption - * - * Draw the window caption. - * The correct pen for the window frame must be selected in the DC. - */ -static void NC_DrawCaption( HDC hdc, RECT *rect, HWND hwnd, - DWORD style, WINBOOL active ) -{ - RECT r = *rect; - WND * wndPtr = WIN_FindWndPtr( hwnd ); - char buffer[256]; - -// if (wndPtr->flags & WIN_MANAGED) return; - - if (!hbitmapClose) - { - if (!(hbitmapClose = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_CLOSE) ))) - return; - hbitmapCloseD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_CLOSE) ); - hbitmapMinimize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCE) ); - hbitmapMinimizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCED) ); - hbitmapMaximize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOM) ); - hbitmapMaximizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOMD) ); - hbitmapRestore = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORE) ); - hbitmapRestoreD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORED) ); - } - - if (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) - { - HBRUSH hbrushOld = SelectObject(hdc, GetSysColorBrush(COLOR_WINDOW) ); - PatBlt( hdc, r.left, r.top, 1, r.bottom-r.top+1,PATCOPY ); - PatBlt( hdc, r.right-1, r.top, 1, r.bottom-r.top+1, PATCOPY ); - PatBlt( hdc, r.left, r.top-1, r.right-r.left, 1, PATCOPY ); - r.left++; - r.right--; - SelectObject( hdc, hbrushOld ); - } - - MoveToEx( hdc, r.left, r.bottom,NULL ); - LineTo( hdc, r.right, r.bottom ); - - if (style & WS_SYSMENU) - { - NC_DrawSysButton( hwnd, hdc, FALSE ); - r.left += SYSMETRICS_CXSIZE + 1; - MoveToEx( hdc, r.left - 1, r.top,NULL ); - LineTo( hdc, r.left - 1, r.bottom ); - } - if (style & WS_MAXIMIZEBOX) - { - NC_DrawMaxButton( hwnd, hdc, FALSE ); - r.right -= SYSMETRICS_CXSIZE + 1; - } - if (style & WS_MINIMIZEBOX) - { - NC_DrawMinButton( hwnd, hdc, FALSE ); - r.right -= SYSMETRICS_CXSIZE + 1; - } - - FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : - COLOR_INACTIVECAPTION) ); - - if (GetWindowTextA( hwnd, buffer, sizeof(buffer) )) - { - if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) ); - else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ); - SetBkMode( hdc, TRANSPARENT ); - DrawTextA( hdc, buffer, -1, &r, - DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX ); - - - } -} - - -/****************************************************************************** - * - * NC_DrawCaption95( - * HDC hdc, - * RECT *rect, - * HWND hwnd, - * DWORD style, - * WINBOOL active ) - * - * Draw the window caption for Win95 style windows. - * The correct pen for the window frame must be selected in the DC. - * - * Bugs - * Hey, a function that finally works! Well, almost. - * It's being worked on. - * - * Revision history - * 05-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original implementation. - * 02-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Some minor fixes. - * - *****************************************************************************/ - -void NC_DrawCaption95( - HDC hdc, - RECT *rect, - HWND hwnd, - DWORD style, - DWORD exStyle, - WINBOOL active ) -{ - RECT r = *rect; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - char buffer[256]; - HPEN hPrevPen; - int txtlen; - -// if (wndPtr->flags & WIN_MANAGED) return; - - hPrevPen = SelectObject( hdc, GetSysColorPen(COLOR_3DFACE) ); - MoveToEx( hdc, r.left, r.bottom - 1, NULL ); - LineTo( hdc, r.right, r.bottom - 1 ); - SelectObject( hdc, hPrevPen ); - r.bottom - 2; - - - FillRect( hdc, &r, GetSysColorBrush(active ? COLOR_ACTIVECAPTION : - COLOR_INACTIVECAPTION) ); - - if (!hbitmapClose) { - if (!(hbitmapClose = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_CLOSE) ))) - return; - hbitmapMinimize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCE) ); - hbitmapMinimizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_REDUCED) ); - hbitmapMaximize = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOM) ); - hbitmapMaximizeD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_ZOOMD) ); - hbitmapRestore = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORE) ); - hbitmapRestoreD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORED) ); - } - - if ((style & WS_SYSMENU) && !(exStyle & WS_EX_TOOLWINDOW)) { - if (NC_DrawSysButton95 (hwnd, hdc, FALSE)) - r.left += sysMetrics[SM_CYCAPTION] - 1; - } - if (style & WS_SYSMENU) { - NC_DrawCloseButton95 (hwnd, hdc, FALSE); - r.right -= sysMetrics[SM_CYCAPTION] - 1; - } - if (style & WS_MAXIMIZEBOX) { - NC_DrawMaxButton95( hwnd, hdc, FALSE ); - r.right -= SYSMETRICS_CXSIZE + 1; - } - if (style & WS_MINIMIZEBOX) { - NC_DrawMinButton95( hwnd, hdc, FALSE ); - r.right -= SYSMETRICS_CXSIZE + 1; - } - - if ( wndPtr->class->bUnicode ) - txtlen = GetWindowTextW( hwnd, buffer, sizeof(buffer) ); - else - txtlen = GetWindowTextA( hwnd, buffer, sizeof(buffer) ); - - - if (txtlen > 0 && txtlen < sizeof(buffer) ) { - NONCLIENTMETRICS nclm; - HFONT hFont, hOldFont; - nclm.cbSize = sizeof(NONCLIENTMETRICS); - SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0); - if (exStyle & WS_EX_TOOLWINDOW) - hFont = CreateFontIndirectA (&nclm.lfSmCaptionFont); - else - hFont = CreateFontIndirectA (&nclm.lfCaptionFont); - hOldFont = SelectObject (hdc, hFont); - if (active) SetTextColor( hdc, GetSysColor( COLOR_CAPTIONTEXT ) ); - else SetTextColor( hdc, GetSysColor( COLOR_INACTIVECAPTIONTEXT ) ); - SetBkMode( hdc, TRANSPARENT ); - r.left += 2; - if ( wndPtr->class->bUnicode ) - DrawTextW( hdc, buffer, -1, &r, - DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT ); - else { - DrawTextA( hdc, buffer, -1, &r, - DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT ); - } - DeleteObject(SelectObject (hdc, hOldFont)); - } -} - - - -/*********************************************************************** - * NC_DoNCPaint - * - * Paint the non-client area. clip is currently unused. - */ -void NC_DoNCPaint( WND* wndPtr, HRGN clip, WINBOOL suppress_menupaint ) -{ - HDC hdc; - RECT rect; - WINBOOL active; - HWND hwnd = wndPtr->hwndSelf; - - if ( wndPtr->dwStyle & WS_MINIMIZE || - !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */ - - active = wndPtr->flags & WIN_NCACTIVATED; - - DPRINT( "%04x %d\n", hwnd, active ); - - if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return; - - if (ExcludeClipRect( hdc, wndPtr->rectClient.left-wndPtr->rectWindow.left, - wndPtr->rectClient.top-wndPtr->rectWindow.top, - wndPtr->rectClient.right-wndPtr->rectWindow.left, - wndPtr->rectClient.bottom-wndPtr->rectWindow.top ) - == NULLREGION) - { - ReleaseDC( hwnd, hdc ); - return; - } - - rect.top = rect.left = 0; - rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left; - rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top; - - - SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) ); - -// if (!(wndPtr->flags & WIN_MANAGED)) - { - if ((wndPtr->dwStyle & WS_BORDER) || (wndPtr->dwStyle & WS_DLGFRAME) || - (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME)) - { - SelectObject( hdc, GetStockObject(NULL_BRUSH) ); - Rectangle( hdc, rect.top, rect.left, rect.right, rect.bottom ); - InflateRect( &rect, -1, -1 ); - } - - if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle )) - NC_DrawFrame( hdc, &rect, TRUE, active ); - else if (wndPtr->dwStyle & WS_THICKFRAME) - NC_DrawFrame(hdc, &rect, FALSE, active ); - - if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION) - { - RECT r = rect; - r.bottom = rect.top + SYSMETRICS_CYSIZE; - rect.top += SYSMETRICS_CYSIZE + SYSMETRICS_CYBORDER; - NC_DrawCaption( hdc, &r, hwnd, wndPtr->dwStyle, active ); - } - } - - if (HAS_MENU(wndPtr)) - { - RECT r = rect; - r.bottom = rect.top + SYSMETRICS_CYMENU; /* default height */ - rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ); - } - - /* Draw the scroll-bars */ - - if (wndPtr->dwStyle & WS_VSCROLL) - SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE ); - if (wndPtr->dwStyle & WS_HSCROLL) - SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE ); - - /* Draw the "size-box" */ - - if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL)) - { - RECT r = rect; - r.left = r.right - SYSMETRICS_CXVSCROLL + 1; - r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1; - if(wndPtr->dwStyle & WS_BORDER) { - r.left++; - r.top++; - } - FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) ); - } - - ReleaseDC( hwnd, hdc ); -} - - -/****************************************************************************** - * - * void NC_DoNCPaint95( - * WND *wndPtr, - * HRGN clip, - * WINBOOL suppress_menupaint ) - * - * Paint the non-client area for Win95 windows. The clip region is - * currently ignored. - * - * Bugs - * grep -E -A10 -B5 \(95\)\|\(Bugs\)\|\(FIXME\) windows/nonclient.c \ - * misc/tweak.c controls/menu.c # :-) - * - * Revision history - * 03-Jul-1997 Dave Cuthbert (dacut@ece.cmu.edu) - * Original implementation - * 10-Jun-1998 Eric Kohl (ekohl@abo.rhein-zeitung.de) - * Fixed some bugs. - * - *****************************************************************************/ - -void NC_DoNCPaint95( - WND *wndPtr, - HRGN clip, - WINBOOL suppress_menupaint ) -{ - HDC hdc; - RECT rect; - WINBOOL active; - HWND hwnd = wndPtr->hwndSelf; - - if ( wndPtr->dwStyle & WS_MINIMIZE || - !WIN_IsWindowDrawable( wndPtr, 0 )) return; /* Nothing to do */ - - active = wndPtr->flags & WIN_NCACTIVATED; - - DPRINT( "%04x %d\n", hwnd, active ); - - if (!(hdc = GetDCEx( hwnd, 0, DCX_USESTYLE | DCX_WINDOW ))) return; - - if (ExcludeClipRect( hdc, wndPtr->rectClient.left -wndPtr->rectWindow.left, - wndPtr->rectClient.top -wndPtr->rectWindow.top, - wndPtr->rectClient.right -wndPtr->rectWindow.left, - wndPtr->rectClient.bottom -wndPtr->rectWindow.top ) - == NULLREGION) - { - ReleaseDC( hwnd, hdc ); - return; - } - - - - rect.top = rect.left = 0; - rect.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left; - rect.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top; - - //rect = wndPtr->rectWindow; - - DPRINT("::%d %d\n", rect.right, rect.bottom); - - - SelectObject( hdc, GetSysColorPen(COLOR_WINDOWFRAME) ); - - //if((wndPtr->flags & WIN_MANAGED)) { - if ((wndPtr->dwStyle & WS_BORDER) && ((wndPtr->dwStyle & WS_DLGFRAME) || - (wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) || (wndPtr->dwStyle & WS_THICKFRAME))) { - DrawEdge(hdc, &rect, EDGE_RAISED, BF_RECT | BF_ADJUST); - } - - if (HAS_FIXEDFRAME( wndPtr->dwStyle, wndPtr->dwExStyle )) - NC_DrawFrame95( hdc, &rect, TRUE, active ); - else if (wndPtr->dwStyle & WS_THICKFRAME) - NC_DrawFrame95(hdc, &rect, FALSE, active ); - - if ((wndPtr->dwStyle & WS_CAPTION) == WS_CAPTION) - { - RECT r = rect; - if (wndPtr->dwExStyle & WS_EX_TOOLWINDOW) { - r.bottom = rect.top + sysMetrics[SM_CYSMCAPTION]; - rect.top += sysMetrics[SM_CYSMCAPTION]; - } - else { - r.bottom = rect.top + sysMetrics[SM_CYCAPTION]; - rect.top += sysMetrics[SM_CYCAPTION]; - } - NC_DrawCaption95 (hdc, &r, hwnd, wndPtr->dwStyle, - wndPtr->dwExStyle, active); - } - //} - - if (HAS_MENU(wndPtr)) - { - RECT r = rect; - r.bottom = rect.top + sysMetrics[SM_CYMENU]; - - DPRINT( "Calling DrawMenuBar with " - "rect (%d, %d)-(%d, %d)\n", r.left, r.top, - r.right, r.bottom); - - rect.top += MENU_DrawMenuBar( hdc, &r, hwnd, suppress_menupaint ) + 1; - } - - DPRINT( "After MenuBar, rect is (%d, %d)-(%d, %d).\n", - rect.left, rect.top, rect.right, rect.bottom ); - - if (wndPtr->dwExStyle & WS_EX_CLIENTEDGE) - DrawEdge(hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); - - if (wndPtr->dwExStyle & WS_EX_STATICEDGE) - DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT | BF_ADJUST); - - /* Draw the scroll-bars */ - - if (wndPtr->dwStyle & WS_VSCROLL) - SCROLL_DrawScrollBar( hwnd, hdc, SB_VERT, TRUE, TRUE ); - if (wndPtr->dwStyle & WS_HSCROLL) - SCROLL_DrawScrollBar( hwnd, hdc, SB_HORZ, TRUE, TRUE ); - - /* Draw the "size-box" */ - if ((wndPtr->dwStyle & WS_VSCROLL) && (wndPtr->dwStyle & WS_HSCROLL)) - { - RECT r = rect; - r.left = r.right - SYSMETRICS_CXVSCROLL + 1; - r.top = r.bottom - SYSMETRICS_CYHSCROLL + 1; - FillRect( hdc, &r, GetSysColorBrush(COLOR_SCROLLBAR) ); - } - - ReleaseDC( hwnd, hdc ); -} - - - - -/*********************************************************************** - * NC_HandleNCPaint - * - * Handle a WM_NCPAINT message. Called from DefWindowProc(). - */ -LONG NC_HandleNCPaint( HWND hwnd , HRGN clip) -{ - WND* wndPtr = WIN_FindWndPtr( hwnd ); - - //if( wndPtr && wndPtr->dwStyle & WS_VISIBLE ) - { - if( wndPtr->dwStyle & WS_MINIMIZE ) - WINPOS_RedrawIconTitle( hwnd ); - else if (TWEAK_WineLook == WIN31_LOOK) - NC_DoNCPaint( wndPtr, clip, FALSE ); - else - NC_DoNCPaint95( wndPtr, clip, FALSE ); - } - return 0; -} - - -/*********************************************************************** - * NC_HandleNCActivate - * - * Handle a WM_NCACTIVATE message. Called from DefWindowProc(). - */ -LONG NC_HandleNCActivate( WND *wndPtr, WPARAM wParam ) -{ - WORD wStateChange; - -// if( wParam ) wStateChange = !(wndPtr->flags & WIN_NCACTIVATED); -// else wStateChange = wndPtr->flags & WIN_NCACTIVATED; - -// if( wStateChange ) - { - if (wParam) wndPtr->flags |= WIN_NCACTIVATED; - else wndPtr->flags &= ~WIN_NCACTIVATED; - - if( wndPtr->dwStyle & WS_MINIMIZE ) - WINPOS_RedrawIconTitle( wndPtr->hwndSelf ); - else if (TWEAK_WineLook == WIN31_LOOK) - NC_DoNCPaint( wndPtr, (HRGN)1, FALSE ); - else - NC_DoNCPaint95( wndPtr, (HRGN)1, FALSE ); - } - return TRUE; -} - - -/*********************************************************************** - * NC_HandleSetCursor - * - * Handle a WM_SETCURSOR message. Called from DefWindowProc(). - */ -LONG NC_HandleSetCursor( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - if (hwnd != (HWND)wParam) return 0; /* Don't set the cursor for child windows */ - - switch(LOWORD(lParam)) - { - case HTERROR: - { - WORD msg = HIWORD( lParam ); - if ((msg == WM_LBUTTONDOWN) || (msg == WM_MBUTTONDOWN) || - (msg == WM_RBUTTONDOWN)) - MessageBeep(0); - } - break; - - case HTCLIENT: - { - WND *wndPtr; - if (!(wndPtr = WIN_FindWndPtr( hwnd ))) break; - if (wndPtr->class->hCursor) - { - SetCursor( wndPtr->class->hCursor ); - return TRUE; - } - else return FALSE; - } - - case HTLEFT: - case HTRIGHT: - return (LONG)SetCursor( LoadCursorA( 0, IDC_SIZEWE ) ); - - case HTTOP: - case HTBOTTOM: - return (LONG)SetCursor( LoadCursorA( 0, IDC_SIZENS ) ); - - case HTTOPLEFT: - case HTBOTTOMRIGHT: - return (LONG)SetCursor( LoadCursorA( 0, IDC_SIZENWSE ) ); - - case HTTOPRIGHT: - case HTBOTTOMLEFT: - return (LONG)SetCursor( LoadCursorA( 0, IDC_SIZENESW ) ); - } - - /* Default cursor: arrow */ - return (LONG)SetCursor( LoadCursorA( 0, IDC_ARROW ) ); -} - -/*********************************************************************** - * NC_GetSysPopupPos - */ -WINBOOL NC_GetSysPopupPos( WND* wndPtr, RECT* rect ) -{ - if( wndPtr->hSysMenu ) - { - if( wndPtr->dwStyle & WS_MINIMIZE ) - GetWindowRect( wndPtr->hwndSelf, rect ); - else - { - if (TWEAK_WineLook == WIN31_LOOK) - NC_GetInsideRect( wndPtr->hwndSelf, rect ); - else - NC_GetInsideRect95( wndPtr->hwndSelf, rect ); - OffsetRect( rect, wndPtr->rectWindow.left, wndPtr->rectWindow.top); - if (wndPtr->dwStyle & WS_CHILD) - ClientToScreen( wndPtr->parent->hwndSelf, (POINT *)rect ); - if (TWEAK_WineLook == WIN31_LOOK) { - rect->right = rect->left + SYSMETRICS_CXSIZE; - rect->bottom = rect->top + SYSMETRICS_CYSIZE; - } - else { - rect->right = rect->left + sysMetrics[SM_CYCAPTION] - 1; - rect->bottom = rect->top + sysMetrics[SM_CYCAPTION] - 1; - } - } - return TRUE; - } - return FALSE; -} - -/*********************************************************************** - * NC_StartSizeMove - * - * Initialisation of a move or resize, when initiatied from a menu choice. - * Return hit test code for caption or sizing border. - */ -static LONG NC_StartSizeMove( WND* wndPtr, WPARAM wParam, - POINT *capturePoint ) -{ - LONG hittest = 0; - POINT pt; - MSG msg; - - if ((wParam & 0xfff0) == SC_MOVE) - { - /* Move pointer at the center of the caption */ - RECT rect; - if (TWEAK_WineLook == WIN31_LOOK) - NC_GetInsideRect( wndPtr->hwndSelf, &rect ); - else - NC_GetInsideRect95( wndPtr->hwndSelf, &rect ); - if (wndPtr->dwStyle & WS_SYSMENU) - rect.left += SYSMETRICS_CXSIZE + 1; - if (wndPtr->dwStyle & WS_MINIMIZEBOX) - rect.right -= SYSMETRICS_CXSIZE + 1; - if (wndPtr->dwStyle & WS_MAXIMIZEBOX) - rect.right -= SYSMETRICS_CXSIZE + 1; - pt.x = wndPtr->rectWindow.left + (rect.right - rect.left) / 2; - pt.y = wndPtr->rectWindow.top + rect.top + SYSMETRICS_CYSIZE/2; - hittest = HTCAPTION; - *capturePoint = pt; - } - else /* SC_SIZE */ - { - while(!hittest) - { - MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE ); - switch(msg.message) - { - case WM_MOUSEMOVE: - hittest = NC_HandleNCHitTest( wndPtr->hwndSelf, msg.pt ); - pt = msg.pt; - if ((hittest < HTLEFT) || (hittest > HTBOTTOMRIGHT)) - hittest = 0; - break; - - case WM_LBUTTONUP: - return 0; - - case WM_KEYDOWN: - switch(msg.wParam) - { - case VK_UP: - hittest = HTTOP; - pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2; - pt.y = wndPtr->rectWindow.top + SYSMETRICS_CYFRAME / 2; - break; - case VK_DOWN: - hittest = HTBOTTOM; - pt.x =(wndPtr->rectWindow.left+wndPtr->rectWindow.right)/2; - pt.y = wndPtr->rectWindow.bottom - SYSMETRICS_CYFRAME / 2; - break; - case VK_LEFT: - hittest = HTLEFT; - pt.x = wndPtr->rectWindow.left + SYSMETRICS_CXFRAME / 2; - pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2; - break; - case VK_RIGHT: - hittest = HTRIGHT; - pt.x = wndPtr->rectWindow.right - SYSMETRICS_CXFRAME / 2; - pt.y =(wndPtr->rectWindow.top+wndPtr->rectWindow.bottom)/2; - break; - case VK_RETURN: - case VK_ESCAPE: return 0; - } - } - } - *capturePoint = pt; - } - SetCursorPos( pt.x, pt.y ); - NC_HandleSetCursor( wndPtr->hwndSelf, - wndPtr->hwndSelf, MAKELONG( hittest, WM_MOUSEMOVE )); - return hittest; -} - - -/*********************************************************************** - * NC_DoSizeMove - * - * Perform SC_MOVE and SC_SIZE commands. - */ -static void NC_DoSizeMove( HWND hwnd, WORD wParam ) -{ - MSG msg; - RECT sizingRect, mouseRect; - HDC hdc; - LONG hittest = (LONG)(wParam & 0x0f); - HCURSOR hDragCursor = 0, hOldCursor = 0; - POINT minTrack, maxTrack; - POINT capturePoint, pt; - WND * wndPtr = WIN_FindWndPtr( hwnd ); - WINBOOL thickframe = HAS_THICKFRAME( wndPtr->dwStyle ); - WINBOOL iconic = wndPtr->dwStyle & WS_MINIMIZE; - WINBOOL moved = FALSE; - DWORD dwPoint = GetMessagePos (); - - capturePoint = pt = *(POINT*)&dwPoint; - -// || (wndPtr->flags & WIN_MANAGED) - if (IsZoomed(hwnd) || !IsWindowVisible(hwnd) ) - return; - - if ((wParam & 0xfff0) == SC_MOVE) - { - if (!(wndPtr->dwStyle & WS_CAPTION)) return; - if (!hittest) - hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint ); - if (!hittest) return; - } - else /* SC_SIZE */ - { - if (!thickframe) return; - if ( hittest && hittest != HTSYSMENU ) hittest += 2; - else - { - SetCapture(hwnd); - hittest = NC_StartSizeMove( wndPtr, wParam, &capturePoint ); - if (!hittest) - { - ReleaseCapture(); - return; - } - } - } - - /* Get min/max info */ - - WINPOS_GetMinMaxInfo( wndPtr, NULL, NULL, &minTrack, &maxTrack ); - sizingRect = wndPtr->rectWindow; - if (wndPtr->dwStyle & WS_CHILD) - GetClientRect( wndPtr->parent->hwndSelf, &mouseRect ); - else - SetRect(&mouseRect, 0, 0, SYSMETRICS_CXSCREEN, SYSMETRICS_CYSCREEN); - if (ON_LEFT_BORDER(hittest)) - { - mouseRect.left = MAX( mouseRect.left, sizingRect.right-maxTrack.x ); - mouseRect.right = MIN( mouseRect.right, sizingRect.right-minTrack.x ); - } - else if (ON_RIGHT_BORDER(hittest)) - { - mouseRect.left = MAX( mouseRect.left, sizingRect.left+minTrack.x ); - mouseRect.right = MIN( mouseRect.right, sizingRect.left+maxTrack.x ); - } - if (ON_TOP_BORDER(hittest)) - { - mouseRect.top = MAX( mouseRect.top, sizingRect.bottom-maxTrack.y ); - mouseRect.bottom = MIN( mouseRect.bottom,sizingRect.bottom-minTrack.y); - } - else if (ON_BOTTOM_BORDER(hittest)) - { - mouseRect.top = MAX( mouseRect.top, sizingRect.top+minTrack.y ); - mouseRect.bottom = MIN( mouseRect.bottom, sizingRect.top+maxTrack.y ); - } - if (wndPtr->dwStyle & WS_CHILD) - { - MapWindowPoints( wndPtr->parent->hwndSelf, 0, - (LPPOINT)&mouseRect, 2 ); - } - SendMessageA( hwnd, WM_ENTERSIZEMOVE, 0, 0 ); - - if (GetCapture() != hwnd) SetCapture( hwnd ); - - if (wndPtr->dwStyle & WS_CHILD) - { - /* Retrieve a default cache DC (without using the window style) */ - hdc = GetDCEx( wndPtr->parent->hwndSelf, 0, DCX_CACHE ); - } - else - { /* Grab the server only when moving top-level windows without desktop */ - hdc = GetDC( 0 ); - } - -// wndPtr->pDriver->pPreSizeMove(wndPtr); - - if( iconic ) /* create a cursor for dragging */ - { - HICON hIcon = (wndPtr->class->hIcon) ? wndPtr->class->hIcon - : (HICON)SendMessageA( hwnd, WM_QUERYDRAGICON, 0, 0L); -// if( hIcon ) hDragCursor = CURSORICON_IconToCursor( hIcon, TRUE ); - if( !hDragCursor ) iconic = FALSE; - } - - if( !iconic ) NC_DrawMovingFrame( hdc, &sizingRect, thickframe ); - - while(1) - { - int dx = 0, dy = 0; - - MSG_InternalGetMessage( &msg, 0, 0, MSGF_SIZE, PM_REMOVE, FALSE ); - - /* Exit on button-up, Return, or Esc */ - if ((msg.message == WM_LBUTTONUP) || - ((msg.message == WM_KEYDOWN) && - ((msg.wParam == VK_RETURN) || (msg.wParam == VK_ESCAPE)))) break; - - if ((msg.message != WM_KEYDOWN) && (msg.message != WM_MOUSEMOVE)) - continue; /* We are not interested in other messages */ - - dwPoint = GetMessagePos (); - pt = *(POINT*)&dwPoint; - - if (msg.message == WM_KEYDOWN) switch(msg.wParam) - { - case VK_UP: pt.y -= 8; break; - case VK_DOWN: pt.y += 8; break; - case VK_LEFT: pt.x -= 8; break; - case VK_RIGHT: pt.x += 8; break; - } - - pt.x = MAX( pt.x, mouseRect.left ); - pt.x = MIN( pt.x, mouseRect.right ); - pt.y = MAX( pt.y, mouseRect.top ); - pt.y = MIN( pt.y, mouseRect.bottom ); - - dx = pt.x - capturePoint.x; - dy = pt.y - capturePoint.y; - - if (dx || dy) - { - if( !moved ) - { - moved = TRUE; - if( iconic ) /* ok, no system popup tracking */ - { - hOldCursor = SetCursor(hDragCursor); - ShowCursor( TRUE ); - WINPOS_ShowIconTitle( wndPtr, FALSE ); - } - } - - if (msg.message == WM_KEYDOWN) SetCursorPos( pt.x, pt.y ); - else - { - RECT newRect = sizingRect; - - if (hittest == HTCAPTION) OffsetRect( &newRect, dx, dy ); - if (ON_LEFT_BORDER(hittest)) newRect.left += dx; - else if (ON_RIGHT_BORDER(hittest)) newRect.right += dx; - if (ON_TOP_BORDER(hittest)) newRect.top += dy; - else if (ON_BOTTOM_BORDER(hittest)) newRect.bottom += dy; - if( !iconic ) - { - NC_DrawMovingFrame( hdc, &sizingRect, thickframe ); - NC_DrawMovingFrame( hdc, &newRect, thickframe ); - } - capturePoint = pt; - sizingRect = newRect; - } - } - } - - ReleaseCapture(); - if( iconic ) - { - if( moved ) /* restore cursors, show icon title later on */ - { - ShowCursor( FALSE ); - SetCursor( hOldCursor ); - } - DestroyCursor( hDragCursor ); - } - else - NC_DrawMovingFrame( hdc, &sizingRect, thickframe ); - - if (wndPtr->dwStyle & WS_CHILD) - ReleaseDC( wndPtr->parent->hwndSelf, hdc ); - else - { - ReleaseDC( 0, hdc ); - } - -// wndPtr->pDriver->pPostSizeMove(wndPtr); - - if (HOOK_IsHooked( WH_CBT )) - { - if ( wndPtr->class->bUnicode == FALSE ) { - if( HOOK_CallHooksA( WH_CBT, HCBT_MOVESIZE,(WPARAM) hwnd,(LPARAM)&sizingRect) ) - sizingRect = wndPtr->rectWindow; - } - else { - if( HOOK_CallHooksW( WH_CBT, HCBT_MOVESIZE, (WPARAM) hwnd,(LPARAM)&sizingRect) ) - sizingRect = wndPtr->rectWindow; - } - } - SendMessageA( hwnd, WM_EXITSIZEMOVE, 0, (LPARAM)0 ); - SendMessageA( hwnd, WM_SETVISIBLE, !IsIconic(hwnd), (LPARAM)0); - - if( moved && !((msg.message == WM_KEYDOWN) && (msg.wParam == VK_ESCAPE)) ) - { - /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */ - SetWindowPos( hwnd, 0, sizingRect.left, sizingRect.top, - sizingRect.right - sizingRect.left, - sizingRect.bottom - sizingRect.top, - ( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 ); - } - - if( IsWindow(hwnd) ) - if( wndPtr->dwStyle & WS_MINIMIZE ) - { - /* Single click brings up the system menu when iconized */ - - if( !moved ) - { - if( wndPtr->dwStyle & WS_SYSMENU ) - SendMessageA( hwnd, WM_SYSCOMMAND, - SC_MOUSEMENU + HTSYSMENU, *((LPARAM*)&pt)); - } - else WINPOS_ShowIconTitle( wndPtr, TRUE ); - } -} - - -/*********************************************************************** - * NC_TrackMinMaxBox - * - * Track a mouse button press on the minimize or maximize box. - */ -static void NC_TrackMinMaxBox( HWND hwnd, WORD wParam ) -{ - MSG msg; - HDC hdc = GetWindowDC( hwnd ); - WINBOOL pressed = TRUE; - void (*paintButton)(HWND, HDC, WINBOOL); - - SetCapture( hwnd ); - if (wParam == HTMINBUTTON) - paintButton = - (TWEAK_WineLook == WIN31_LOOK) ? &NC_DrawMinButton : &NC_DrawMinButton95; - else - paintButton = - (TWEAK_WineLook == WIN31_LOOK) ? &NC_DrawMaxButton : &NC_DrawMaxButton95; - - (*paintButton)( hwnd, hdc, TRUE ); - - do - { - WINBOOL oldstate = pressed; - MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE ); - - pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam); - if (pressed != oldstate) - (*paintButton)( hwnd, hdc, pressed ); - } while (msg.message != WM_LBUTTONUP); - - (*paintButton)( hwnd, hdc, FALSE ); - - ReleaseCapture(); - ReleaseDC( hwnd, hdc ); - if (!pressed) return; - - if (wParam == HTMINBUTTON) - SendMessageA( hwnd, WM_SYSCOMMAND, SC_MINIMIZE, *(LONG*)&msg.pt ); - else - SendMessageA( hwnd, WM_SYSCOMMAND, - IsZoomed(hwnd) ? SC_RESTORE:SC_MAXIMIZE, *(LONG*)&msg.pt ); -} - - -/*********************************************************************** - * NC_TrackCloseButton95 - * - * Track a mouse button press on the Win95 close button. - */ -static void -NC_TrackCloseButton95 (HWND hwnd, WORD wParam) -{ - MSG msg; - HDC hdc = GetWindowDC( hwnd ); - WINBOOL pressed = TRUE; - - SetCapture( hwnd ); - - NC_DrawCloseButton95 (hwnd, hdc, TRUE); - - do - { - WINBOOL oldstate = pressed; - MSG_InternalGetMessage( &msg, 0, 0, 0, PM_REMOVE, FALSE ); - - pressed = (NC_HandleNCHitTest( hwnd, msg.pt ) == wParam); - if (pressed != oldstate) - NC_DrawCloseButton95 (hwnd, hdc, pressed); - } while (msg.message != WM_LBUTTONUP); - - NC_DrawCloseButton95 (hwnd, hdc, FALSE); - - ReleaseCapture(); - ReleaseDC( hwnd, hdc ); - if (!pressed) return; - - SendMessageA( hwnd, WM_SYSCOMMAND, SC_CLOSE, *(LONG*)&msg.pt ); -} - - -/*********************************************************************** - * NC_TrackScrollBar - * - * Track a mouse button press on the horizontal or vertical scroll-bar. - */ -static void NC_TrackScrollBar( HWND hwnd, WPARAM wParam, POINT pt ) -{ - MSG *msg; - INT scrollbar; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - if ((wParam & 0xfff0) == SC_HSCROLL) - { - if ((wParam & 0x0f) != HTHSCROLL) return; - scrollbar = SB_HORZ; - } - else /* SC_VSCROLL */ - { - if ((wParam & 0x0f) != HTVSCROLL) return; - scrollbar = SB_VERT; - } - - if (!(msg = HeapAlloc(GetProcessHeap,0,sizeof(MSG)))) return; - pt.x -= wndPtr->rectWindow.left; - pt.y -= wndPtr->rectWindow.top; - SetCapture( hwnd ); - SCROLL_HandleScrollEvent( hwnd, scrollbar, WM_LBUTTONDOWN, pt ); - - do - { - GetMessageA( (msg), 0, 0, 0 ); - switch(msg->message) - { - case WM_LBUTTONUP: - case WM_MOUSEMOVE: - case WM_SYSTIMER: - pt.x = LOWORD(msg->lParam) + wndPtr->rectClient.left - - wndPtr->rectWindow.left; - pt.y = HIWORD(msg->lParam) + wndPtr->rectClient.top - - wndPtr->rectWindow.top; - SCROLL_HandleScrollEvent( hwnd, scrollbar, msg->message, pt ); - break; - default: - TranslateMessage( msg ); - DispatchMessage( msg ); - break; - } - if (!IsWindow( hwnd )) - { - ReleaseCapture(); - break; - } - } while (msg->message != WM_LBUTTONUP); - HeapFree(GetProcessHeap(),0,msg); -} - -/*********************************************************************** - * NC_HandleNCLButtonDown - * - * Handle a WM_NCLBUTTONDOWN message. Called from DefWindowProc(). - */ -LONG NC_HandleNCLButtonDown( WND* pWnd, WPARAM wParam, LPARAM lParam ) -{ - HWND hwnd = pWnd->hwndSelf; - - switch(wParam) /* Hit test */ - { - case HTCAPTION: - hwnd = WIN_GetTopParent(hwnd); - - if( WINPOS_SetActiveWindow(hwnd, TRUE, TRUE) || (GetActiveWindow() == hwnd) ) - SendMessageA( pWnd->hwndSelf, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, lParam ); - break; - - case HTSYSMENU: - if( pWnd->dwStyle & WS_SYSMENU ) - { - if( !(pWnd->dwStyle & WS_MINIMIZE) ) - { - HDC hDC = GetWindowDC(hwnd); - if (TWEAK_WineLook == WIN31_LOOK) - NC_DrawSysButton( hwnd, hDC, TRUE ); - else - NC_DrawSysButton95( hwnd, hDC, TRUE ); - ReleaseDC( hwnd, hDC ); - } - SendMessageA( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU + HTSYSMENU, lParam ); - } - break; - - case HTMENU: - SendMessageA( hwnd, WM_SYSCOMMAND, SC_MOUSEMENU, lParam ); - break; - - case HTHSCROLL: - SendMessageA( hwnd, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, lParam ); - break; - - case HTVSCROLL: - SendMessageA( hwnd, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, lParam ); - break; - - case HTMINBUTTON: - case HTMAXBUTTON: - NC_TrackMinMaxBox( hwnd, wParam ); - break; - - case HTCLOSE: - if (TWEAK_WineLook >= WIN95_LOOK) - NC_TrackCloseButton95 (hwnd, wParam); - break; - - case HTLEFT: - case HTRIGHT: - case HTTOP: - case HTTOPLEFT: - case HTTOPRIGHT: - case HTBOTTOM: - case HTBOTTOMLEFT: - case HTBOTTOMRIGHT: - /* make sure hittest fits into 0xf and doesn't overlap with HTSYSMENU */ - SendMessageA( hwnd, WM_SYSCOMMAND, SC_SIZE + wParam - 2, lParam); - break; - - case HTBORDER: - break; - } - return 0; -} - - -/*********************************************************************** - * NC_HandleNCLButtonDblClk - * - * Handle a WM_NCLBUTTONDBLCLK message. Called from DefWindowProc(). - */ -LONG NC_HandleNCLButtonDblClk( WND *pWnd, WPARAM wParam, LPARAM lParam ) -{ - /* - * if this is an icon, send a restore since we are handling - * a double click - */ - if (pWnd->dwStyle & WS_MINIMIZE) - { - SendMessageA( pWnd->hwndSelf, WM_SYSCOMMAND, SC_RESTORE, lParam ); - return 0; - } - - switch(wParam) /* Hit test */ - { - case HTCAPTION: - /* stop processing if WS_MAXIMIZEBOX is missing */ - if (pWnd->dwStyle & WS_MAXIMIZEBOX) - SendMessageA( pWnd->hwndSelf, WM_SYSCOMMAND, - (pWnd->dwStyle & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE, - lParam ); - break; - - case HTSYSMENU: - if (!(pWnd->class->style & CS_NOCLOSE)) - SendMessageA( pWnd->hwndSelf, WM_SYSCOMMAND, SC_CLOSE, lParam ); - break; - - case HTHSCROLL: - SendMessageA( pWnd->hwndSelf, WM_SYSCOMMAND, SC_HSCROLL + HTHSCROLL, - lParam ); - break; - - case HTVSCROLL: - SendMessageA( pWnd->hwndSelf, WM_SYSCOMMAND, SC_VSCROLL + HTVSCROLL, - lParam ); - break; - } - return 0; -} - - -/*********************************************************************** - * NC_HandleSysCommand - * - * Handle a WM_SYSCOMMAND message. Called from DefWindowProc(). - */ -LONG NC_HandleSysCommand( HWND hwnd, WPARAM wParam, POINT pt ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - UINT uCommand = wParam & 0xFFF0; - - DPRINT( "Handling WM_SYSCOMMAND %x %d,%d\n", - wParam, pt.x, pt.y ); - - if (wndPtr->dwStyle & WS_CHILD && uCommand != SC_KEYMENU ) - ScreenToClient( wndPtr->parent->hwndSelf, &pt ); - - switch (uCommand) - { - case SC_SIZE: - case SC_MOVE: - NC_DoSizeMove( hwnd, wParam ); - break; - - case SC_MINIMIZE: - ShowWindow( hwnd, SW_MINIMIZE ); - break; - - case SC_MAXIMIZE: - ShowWindow( hwnd, SW_MAXIMIZE ); - break; - - case SC_RESTORE: - ShowWindow( hwnd, SW_RESTORE ); - break; - - case SC_CLOSE: - return SendMessageA( hwnd, WM_CLOSE, 0, 0 ); - - case SC_VSCROLL: - case SC_HSCROLL: - NC_TrackScrollBar( hwnd, wParam, pt ); - break; - - case SC_MOUSEMENU: - MENU_TrackMouseMenuBar( wndPtr, wParam & 0x000F, pt ); - break; - - case SC_KEYMENU: - MENU_TrackKbdMenuBar( wndPtr , wParam , pt.x ); - break; - - case SC_TASKLIST: - WinExec( "taskman.exe", SW_SHOWNORMAL ); - break; - - case SC_SCREENSAVE: - if (wParam == SC_ABOUTWINE) { - //ShellAboutA(hwnd,"Wine", WINE_RELEASE_INFO, 0); - } - else - if (wParam == SC_PUTMARK) - DPRINT("Mark requested by user\n"); - break; - - case SC_HOTKEY: - case SC_ARRANGE: - case SC_NEXTWINDOW: - case SC_PREVWINDOW: - DPRINT( "unimplemented!\n"); - break; - } - return 0; -} - - -/*********************************************************************** - * FastWindowFrame (GDI.400) - */ -WINBOOL STDCALL FastWindowFrame( HDC hdc, const RECT *rect, - INT width, INT height, DWORD rop ) -{ - HBRUSH hbrush = SelectObject( hdc, GetStockObject( GRAY_BRUSH ) ); - PatBlt( hdc, rect->left, rect->top, - rect->right - rect->left - width, height, rop ); - PatBlt( hdc, rect->left, rect->top + height, width, - rect->bottom - rect->top - height, rop ); - PatBlt( hdc, rect->left + width, rect->bottom, - rect->right - rect->left - width, -height, rop ); - PatBlt( hdc, rect->right, rect->top, -width, - rect->bottom - rect->top - height, rop ); - SelectObject( hdc, hbrush ); - return TRUE; -} diff --git a/reactos/lib/user32/internal/paint.c b/reactos/lib/user32/internal/paint.c deleted file mode 100644 index 7ddc03d1d30..00000000000 --- a/reactos/lib/user32/internal/paint.c +++ /dev/null @@ -1,283 +0,0 @@ - -#include -#include - -/* - * Window painting functions - * - * Copyright 1993, 1994, 1995 Alexandre Julliard - * - * FIXME: Do not repaint full nonclient area all the time. Instead, compute - * intersection with hrgnUpdate (which should be moved from client to - * window coords as well, lookup 'the pain' comment in the winpos.c). - */ - - /* Last CTLCOLOR id */ -//#define CTLCOLOR_MAX CTLCOLOR_STATIC - -HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType ); - - -/*********************************************************************** - * PAINT_RedrawWindow - * - * FIXME: Windows uses WM_SYNCPAINT to cut down the number of intertask - * SendMessage() calls. This is a comment inside DefWindowProc() source - * from 16-bit SDK: - * - * This message avoids lots of inter-app message traffic - * by switching to the other task and continuing the - * recursion there. - * - * wParam = flags - * LOWORD(lParam) = hrgnClip - * HIWORD(lParam) = hwndSkip (not used; always NULL) - * - * All in all, a prime candidate for a rewrite. - */ -WINBOOL PAINT_RedrawWindow( HWND hwnd, const RECT *rectUpdate, - HRGN hrgnUpdate, UINT flags, UINT control ) -{ - WINBOOL bIcon; - HRGN hrgn; - RECT rectClient; - WND* wndPtr; - WND **list, **ppWnd; - - if (!hwnd) hwnd = GetDesktopWindow(); - if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return FALSE; - -#ifdef OPTIMIZE - if (!WIN_IsWindowDrawable( wndPtr, !(flags & RDW_FRAME) ) ) - return TRUE; /* No redraw needed */ -#endif - - bIcon = (wndPtr->dwStyle & WS_MINIMIZE && wndPtr->class->hIcon); - - GetClientRect( hwnd, &rectClient ); - - OffsetRect(&rectClient,5,16); - - if (flags & RDW_INVALIDATE) /* Invalidate */ - { - int rgnNotEmpty = COMPLEXREGION; - - if (wndPtr->hrgnUpdate > (HRGN)1) /* Is there already an update region? */ - { - if ((hrgn = hrgnUpdate) == 0) - hrgn = CreateRectRgnIndirect( rectUpdate ? rectUpdate : - &rectClient ); - rgnNotEmpty = CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, - hrgn, RGN_OR ); - if (!hrgnUpdate) DeleteObject( hrgn ); - } - else /* No update region yet */ - { - if (!(wndPtr->flags & WIN_INTERNAL_PAINT)) - QUEUE_IncPaintCount( wndPtr->hmemTaskQ ); - if (hrgnUpdate) - { - wndPtr->hrgnUpdate = CreateRectRgn( 0, 0, 0, 0 ); - rgnNotEmpty = CombineRgn( wndPtr->hrgnUpdate, hrgnUpdate, - 0, RGN_COPY ); - } - else wndPtr->hrgnUpdate = CreateRectRgnIndirect( rectUpdate ? - rectUpdate : &rectClient ); - } - - if (flags & RDW_FRAME) wndPtr->flags |= WIN_NEEDS_NCPAINT; - - /* restrict update region to client area (FIXME: correct?) */ - if (wndPtr->hrgnUpdate) - { - HRGN clientRgn = CreateRectRgnIndirect( &rectClient ); - rgnNotEmpty = CombineRgn( wndPtr->hrgnUpdate, clientRgn, - wndPtr->hrgnUpdate, RGN_AND ); - DeleteObject( clientRgn ); - } - - /* check for bogus update region */ - if ( rgnNotEmpty == NULLREGION ) - { - wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND; - DeleteObject( wndPtr->hrgnUpdate ); - wndPtr->hrgnUpdate=0; - if (!(wndPtr->flags & WIN_INTERNAL_PAINT)) - QUEUE_DecPaintCount( wndPtr->hmemTaskQ ); - } - else - if (flags & RDW_ERASE) wndPtr->flags |= WIN_NEEDS_ERASEBKGND; - flags |= RDW_FRAME; /* Force children frame invalidation */ - } - else if (flags & RDW_VALIDATE) /* Validate */ - { - /* We need an update region in order to validate anything */ - if (wndPtr->hrgnUpdate > (HRGN)1) - { - if (!hrgnUpdate && !rectUpdate) - { - /* Special case: validate everything */ - DeleteObject( wndPtr->hrgnUpdate ); - wndPtr->hrgnUpdate = 0; - } - else - { - if ((hrgn = hrgnUpdate) == 0) - hrgn = CreateRectRgnIndirect( rectUpdate ); - if (CombineRgn( wndPtr->hrgnUpdate, wndPtr->hrgnUpdate, - hrgn, RGN_DIFF ) == NULLREGION) - { - DeleteObject( wndPtr->hrgnUpdate ); - wndPtr->hrgnUpdate = 0; - } - if (!hrgnUpdate) DeleteObject( hrgn ); - } - if (!wndPtr->hrgnUpdate) /* No more update region */ - if (!(wndPtr->flags & WIN_INTERNAL_PAINT)) - QUEUE_DecPaintCount( wndPtr->hmemTaskQ ); - } - if (flags & RDW_NOFRAME) wndPtr->flags &= ~WIN_NEEDS_NCPAINT; - if (flags & RDW_NOERASE) wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND; - } - - /* Set/clear internal paint flag */ - - if (flags & RDW_INTERNALPAINT) - { - if ( wndPtr->hrgnUpdate <= (HRGN)1 && !(wndPtr->flags & WIN_INTERNAL_PAINT)) - QUEUE_IncPaintCount( wndPtr->hmemTaskQ ); - wndPtr->flags |= WIN_INTERNAL_PAINT; - } - else if (flags & RDW_NOINTERNALPAINT) - { - if ( wndPtr->hrgnUpdate <= (HRGN)1 && (wndPtr->flags & WIN_INTERNAL_PAINT)) - QUEUE_DecPaintCount( wndPtr->hmemTaskQ ); - wndPtr->flags &= ~WIN_INTERNAL_PAINT; - } - - /* Erase/update window */ - - if (flags & RDW_UPDATENOW) - { - if (wndPtr->hrgnUpdate) /* wm_painticon wparam is 1 */ - SendMessageA( hwnd, (bIcon) ? WM_PAINTICON : WM_PAINT, bIcon, 0 ); - } - else -//if (flags & RDW_ERASENOW) - { - //if (wndPtr->flags & WIN_NEEDS_NCPAINT) - WIN_UpdateNCArea( wndPtr, FALSE); - - //if (wndPtr->flags & WIN_NEEDS_ERASEBKGND) - { - HDC hdc = GetDCEx( hwnd, wndPtr->hrgnUpdate, - DCX_INTERSECTRGN | DCX_USESTYLE | - DCX_KEEPCLIPRGN | DCX_WINDOWPAINT | - (bIcon ? DCX_WINDOW : 0) ); - if (hdc) - { - if (SendMessageA( hwnd, (bIcon) ? WM_ICONERASEBKGND - : WM_ERASEBKGND, - (WPARAM)hdc, 0 )) - wndPtr->flags &= ~WIN_NEEDS_ERASEBKGND; - ReleaseDC( hwnd, hdc ); - } - } - } - - /* Recursively process children */ - - if (!(flags & RDW_NOCHILDREN) && - ((flags & RDW_ALLCHILDREN) || !(wndPtr->dwStyle & WS_CLIPCHILDREN)) && - !(wndPtr->dwStyle & WS_MINIMIZE) ) - { - if ( hrgnUpdate || rectUpdate ) - { - if (!(hrgn = CreateRectRgn( 0, 0, 0, 0 ))) return TRUE; - if( !hrgnUpdate ) - { - control |= (RDW_C_DELETEHRGN | RDW_C_USEHRGN); - if( !(hrgnUpdate = CreateRectRgnIndirect( rectUpdate )) ) - { - DeleteObject( hrgn ); - return TRUE; - } - } - if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) ) - { - for (ppWnd = list; *ppWnd; ppWnd++) - { - wndPtr = *ppWnd; - if (!IsWindow(wndPtr->hwndSelf)) continue; - if (wndPtr->dwStyle & WS_VISIBLE) - { - SetRectRgn( hrgn, - wndPtr->rectWindow.left, wndPtr->rectWindow.top, - wndPtr->rectWindow.right, wndPtr->rectWindow.bottom ); - if (CombineRgn( hrgn, hrgn, hrgnUpdate, RGN_AND )) - { - OffsetRgn( hrgn, -wndPtr->rectClient.left, - -wndPtr->rectClient.top ); - PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, hrgn, flags, - RDW_C_USEHRGN ); - } - } - } - HeapFree( GetProcessHeap(), 0, list ); - } - DeleteObject( hrgn ); - if (control & RDW_C_DELETEHRGN) DeleteObject( hrgnUpdate ); - } - else - { - if( (list = WIN_BuildWinArray( wndPtr, 0, NULL )) ) - { - for (ppWnd = list; *ppWnd; ppWnd++) - { - wndPtr = *ppWnd; - if (IsWindow( wndPtr->hwndSelf )) - PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, flags, 0 ); - } - HeapFree( GetProcessHeap(), 0, list ); - } - } - - } - return TRUE; -} - - - -/*********************************************************************** - * GetControlBrush Not A Win32 API - */ -HBRUSH GetControlBrush( HWND hwnd, HDC hdc, UINT ctlType ) -{ - WND* wndPtr = WIN_FindWndPtr( hwnd ); - - if((ctlType <= CTLCOLOR_MAX) && wndPtr ) - { - WND* parent; - if( wndPtr->dwStyle & WS_POPUP ) parent = wndPtr->owner; - else parent = wndPtr->parent; - if( !parent ) parent = wndPtr; - return (HBRUSH)PAINT_GetControlBrush( parent->hwndSelf, hwnd, hdc, ctlType ); - } - return (HBRUSH)0; -} - -/*********************************************************************** - * PAINT_GetControlBrush - */ -HBRUSH PAINT_GetControlBrush( HWND hParent, HWND hWnd, HDC hDC, UINT ctlType ) -{ - LOGBRUSH LogBrush; - HBRUSH bkgBrush = (HBRUSH)SendMessageA( hParent, WM_CTLCOLORMSGBOX + ctlType, - (WPARAM)hDC, (LPARAM)hWnd ); - if( !GetObject(bkgBrush,sizeof(LOGBRUSH),&LogBrush) ) - bkgBrush = DEFWND_ControlColor( hDC, ctlType ); - return bkgBrush; -} - - - diff --git a/reactos/lib/user32/internal/queue.c b/reactos/lib/user32/internal/queue.c deleted file mode 100644 index a3b60afce4a..00000000000 --- a/reactos/lib/user32/internal/queue.c +++ /dev/null @@ -1,707 +0,0 @@ -/* - * Message queues related functions - * - * Copyright 1993, 1994 Alexandre Julliard - */ - -#include -#include -#include -#include - - -HWND GetSysModalWindow(void); - -#define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */ - -static HQUEUE hFirstQueue = 0; -static HQUEUE hExitingQueue = 0; -static HQUEUE hmemSysMsgQueue = 0; -static MESSAGEQUEUE *sysMsgQueue = NULL; - -static MESSAGEQUEUE *pMouseQueue = NULL; /* Queue for last mouse message */ -static MESSAGEQUEUE *pKbdQueue = NULL; /* Queue for last kbd message */ - -MESSAGEQUEUE *pCursorQueue = NULL; -MESSAGEQUEUE *pActiveQueue = NULL; - -/*********************************************************************** - * QUEUE_DumpQueue - */ -void QUEUE_DumpQueue( HQUEUE hQueue ) -{ - MESSAGEQUEUE *pq; - - if (!(pq = (MESSAGEQUEUE*) GlobalLock( hQueue )) || - GlobalSize(hQueue) < sizeof(MESSAGEQUEUE)+pq->queueSize*sizeof(QMSG)) - { - DPRINT( "%04x is not a queue handle\n", hQueue ); - return; - } - - DPRINT( "next: %12.4x Intertask SendMessage:\n" - "hTask: %11.4x ----------------------\n" - "msgSize: %9.4x hWnd: %10.4x\n" - "msgCount: %8.4x msg: %11.4x\n" - "msgNext: %9.4x wParam: %8.4x\n" - "msgFree: %9.4x lParam: %8.8x\n" - "qSize: %11.4x lRet: %10.8x\n" - "wWinVer: %9.4x ISMH: %10.4x\n" - "paints: %10.4x hSendTask: %5.4x\n" - "timers: %10.4x hPrevSend: %5.4x\n" - "wakeBits: %8.4x\n" - "wakeMask: %8.4x\n" - "hCurHook: %8.4x\n", - pq->next, pq->hTask, pq->msgSize, pq->hWnd, - pq->msgCount, pq->msg, pq->nextMessage, pq->wParam, - pq->nextFreeMessage, (unsigned)pq->lParam, pq->queueSize, - (unsigned)pq->SendMessageReturn, pq->wWinVersion, pq->InSendMessageHandle, - pq->wPaintCount, pq->hSendingTask, pq->wTimerCount, - pq->hPrevSendingTask, pq->wakeBits, pq->wakeMask, pq->hCurHook); -} - - -/*********************************************************************** - * QUEUE_WalkQueues - */ -void QUEUE_WalkQueues(void) -{ - char module[10]; - HQUEUE hQueue = hFirstQueue; - - DPRINT( "Queue Size Msgs Task\n" ); - while (hQueue) - { - MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock( hQueue ); - if (!queue) - { - DPRINT( "Bad queue handle %04x\n", hQueue ); - return; - } -// if (!GetModuleFileName( queue->hTask, module, sizeof(module ))) -// strcpy( module, "???" ); -// DPRINT( "%04x %5d %4d %04x %s\n", hQueue, queue->msgSize, -// queue->msgCount, queue->hTask, module ); - hQueue = queue->next; - } - DPRINT( "\n" ); -} - - -/*********************************************************************** - * QUEUE_IsExitingQueue - */ -WINBOOL QUEUE_IsExitingQueue( HQUEUE hQueue ) -{ - return FALSE; -// return (hExitingQueue && (hQueue == hExitingQueue)); -} - - -/*********************************************************************** - * QUEUE_SetExitingQueue - */ -void QUEUE_SetExitingQueue( HQUEUE hQueue ) -{ - hExitingQueue = hQueue; -} - - -/*********************************************************************** - * QUEUE_CreateMsgQueue - * - * Creates a message queue. Doesn't link it into queue list! - */ -HQUEUE QUEUE_CreateMsgQueue( int size ) -{ - HQUEUE hQueue; - MESSAGEQUEUE * msgQueue; - int queueSize; - //TDB *pTask = (TDB *)GlobalLock( GetCurrentTask() ); - - DPRINT("Creating message queue...\n"); - - queueSize = sizeof(MESSAGEQUEUE) + size * sizeof(QMSG); - if (!(hQueue = GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, queueSize ))) - return 0; - msgQueue = (MESSAGEQUEUE *) GlobalLock( hQueue ); - msgQueue->self = hQueue; - msgQueue->msgSize = sizeof(QMSG); - msgQueue->queueSize = size; - msgQueue->wakeBits = msgQueue->changeBits = QS_SMPARAMSFREE; - //msgQueue->wWinVersion = pTask ? pTask->version : 0; - GlobalUnlock( hQueue ); - return hQueue; -} - - -/*********************************************************************** - * QUEUE_DeleteMsgQueue - * - * Unlinks and deletes a message queue. - * - * Note: We need to mask asynchronous events to make sure PostMessage works - * even in the signal handler. - */ -WINBOOL QUEUE_DeleteMsgQueue( HQUEUE hQueue ) -{ - MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)GlobalLock(hQueue); - HQUEUE senderQ; - HQUEUE *pPrev; - - DPRINT("Deleting message queue %04x\n", hQueue); - - if (!hQueue || !msgQueue) - { - DPRINT( "invalid argument.\n"); - return 0; - } - if( pCursorQueue == msgQueue ) pCursorQueue = NULL; - if( pActiveQueue == msgQueue ) pActiveQueue = NULL; - - /* flush sent messages */ - senderQ = msgQueue->hSendingTask; - while( senderQ ) - { - MESSAGEQUEUE* sq = (MESSAGEQUEUE*)GlobalLock(senderQ); - if( !sq ) break; - sq->SendMessageReturn = 0L; - QUEUE_SetWakeBit( sq, QS_SMRESULT ); - senderQ = sq->hPrevSendingTask; - } - - SIGNAL_MaskAsyncEvents( TRUE ); - - pPrev = &hFirstQueue; - while (*pPrev && (*pPrev != hQueue)) - { - MESSAGEQUEUE *msgQ = (MESSAGEQUEUE*)GlobalLock(*pPrev); - pPrev = &msgQ->next; - } - if (*pPrev) *pPrev = msgQueue->next; - msgQueue->self = 0; - - SIGNAL_MaskAsyncEvents( FALSE ); - - GlobalFree( hQueue ); - return 1; -} - - -/*********************************************************************** - * QUEUE_CreateSysMsgQueue - * - * Create the system message queue, and set the double-click speed. - * Must be called only once. - */ -WINBOOL QUEUE_CreateSysMsgQueue( int size ) -{ - if (size > MAX_QUEUE_SIZE) size = MAX_QUEUE_SIZE; - else if (size <= 0) size = 1; - if (!(hmemSysMsgQueue = QUEUE_CreateMsgQueue( size ))) return FALSE; - sysMsgQueue = (MESSAGEQUEUE *) GlobalLock( hmemSysMsgQueue ); - return TRUE; -} - - -/*********************************************************************** - * QUEUE_GetSysQueue - */ -MESSAGEQUEUE *QUEUE_GetSysQueue(void) -{ - return sysMsgQueue; -} - -/*********************************************************************** - * QUEUE_Signal - */ - -void QUEUE_Signal( HTASK hTask ) -{ -#if 0 - PDB32 *pdb; - THREAD_ENTRY *entry; - - TDB *pTask = (TDB *)GlobalLock( hTask ); - if ( !pTask ) return; - - /* Wake up thread waiting for message */ - SetEvent( pTask->thdb->event ); - - PostEvent( hTask ); -#endif -} - -/*********************************************************************** - * QUEUE_Wait - */ -static void QUEUE_Wait( DWORD wait_mask ) -{ -#if 0 - if ( THREAD_IsWin16( THREAD_Current() ) ) - WaitEvent( 0 ); - else - { - DPRINT( "current task is 32-bit, calling SYNC_DoWait\n"); - MsgWaitForMultipleObjects( 0, NULL, FALSE, INFINITE32, wait_mask ); - } -#endif -} - - -/*********************************************************************** - * QUEUE_SetWakeBit - * - * See "Windows Internals", p.449 - */ -void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit ) -{ - DPRINT("queue = %04x (wm=%04x), bit = %04x\n", - queue->self, queue->wakeMask, bit ); - - if (bit & QS_MOUSE) pMouseQueue = queue; - if (bit & QS_KEY) pKbdQueue = queue; - queue->changeBits |= bit; - queue->wakeBits |= bit; - if (queue->wakeMask & bit) - { - queue->wakeMask = 0; - QUEUE_Signal( queue->hTask ); - } -} - - -/*********************************************************************** - * QUEUE_ClearWakeBit - */ -void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit ) -{ - queue->changeBits &= ~bit; - queue->wakeBits &= ~bit; -} - - -/*********************************************************************** - * QUEUE_WaitBits - * - * See "Windows Internals", p.447 - */ -void QUEUE_WaitBits( WORD bits ) -{ - MESSAGEQUEUE *queue; - - DPRINT("q %04x waiting for %04x\n", GetFastQueue(), bits); - - for (;;) - { - if (!(queue = (MESSAGEQUEUE *)( GetFastQueue() ))) return; - - if (queue->changeBits & bits) - { - /* One of the bits is set; we can return */ - queue->wakeMask = 0; - return; - } - if (queue->wakeBits & QS_SENDMESSAGE) - { - /* Process the sent message immediately */ - - queue->wakeMask = 0; - QUEUE_ReceiveMessage( queue ); - continue; /* nested sm crux */ - } - - queue->wakeMask = bits | QS_SENDMESSAGE; - if(queue->changeBits & bits) continue; - - DPRINT("%04x) wakeMask is %04x, waiting\n", queue->self, queue->wakeMask); - - QUEUE_Wait( queue->wakeMask ); - } -} - - -/*********************************************************************** - * QUEUE_ReceiveMessage - * - * This routine is called when a sent message is waiting for the queue. - */ -void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue ) -{ - MESSAGEQUEUE *senderQ = NULL; - HQUEUE prevSender = 0; - QSMCTRL* prevCtrlPtr = NULL; - LRESULT result = 0; - - DPRINT( "ReceiveMessage, queue %04x\n", queue->self ); - if (!(queue->wakeBits & QS_SENDMESSAGE) || - !(senderQ = (MESSAGEQUEUE*)GlobalLock( queue->hSendingTask))) - { DPRINT("\trcm: nothing to do\n"); return; } - - if( !senderQ->hPrevSendingTask ) - QUEUE_ClearWakeBit( queue, QS_SENDMESSAGE ); /* no more sent messages */ - - /* Save current state on stack */ - prevSender = queue->InSendMessageHandle; - prevCtrlPtr = queue->smResultCurrent; - - /* Remove sending queue from the list */ - queue->InSendMessageHandle = queue->hSendingTask; - queue->smResultCurrent = senderQ->smResultInit; - queue->hSendingTask = senderQ->hPrevSendingTask; - - DPRINT( "\trcm: smResultCurrent = %08x, prevCtrl = %08x\n", - (unsigned)queue->smResultCurrent, (unsigned)prevCtrlPtr ); - QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE ); - - DPRINT( "\trcm: calling wndproc - %04x %04x %04x%04x %08x\n", - senderQ->hWnd, senderQ->msg, senderQ->wParamHigh, - senderQ->wParam, (unsigned)senderQ->lParam ); - - if (IsWindow( senderQ->hWnd )) - { - WND *wndPtr = WIN_FindWndPtr( senderQ->hWnd ); - DWORD extraInfo = queue->GetMessageExtraInfoVal; - queue->GetMessageExtraInfoVal = senderQ->GetMessageExtraInfoVal; - - if (senderQ->flags & QUEUE_SM_ASCII) - { - WPARAM wParam = MAKELONG( senderQ->wParam, senderQ->wParamHigh ); - DPRINT( "\trcm: msg is Win32\n" ); - if (senderQ->flags & QUEUE_SM_UNICODE) - result = CallWindowProcW( wndPtr->winproc, - senderQ->hWnd, senderQ->msg, - wParam, senderQ->lParam ); - else - result = CallWindowProcA( wndPtr->winproc, - senderQ->hWnd, senderQ->msg, - wParam, senderQ->lParam ); - } - else /* Win16 message */ - result = CallWindowProc( (WNDPROC)wndPtr->winproc, - senderQ->hWnd, senderQ->msg, - senderQ->wParam, senderQ->lParam ); - - queue->GetMessageExtraInfoVal = extraInfo; /* Restore extra info */ - DPRINT("\trcm: result = %08x\n", (unsigned)result ); - } - else DPRINT( "\trcm: bad hWnd\n"); - - /* Return the result to the sender task */ - ReplyMessage( result ); - - queue->InSendMessageHandle = prevSender; - queue->smResultCurrent = prevCtrlPtr; - - DPRINT("done!\n"); -} - -/*********************************************************************** - * QUEUE_FlushMessage - * - * Try to reply to all pending sent messages on exit. - */ -void QUEUE_FlushMessages( HQUEUE hQueue ) -{ - MESSAGEQUEUE *queue = (MESSAGEQUEUE*)GlobalLock( hQueue ); - - if( queue ) - { - MESSAGEQUEUE *senderQ = (MESSAGEQUEUE*)GlobalLock( queue->hSendingTask); - QSMCTRL* CtrlPtr = queue->smResultCurrent; - - DPRINT("Flushing queue %04x:\n", hQueue ); - - while( senderQ ) - { - if( !CtrlPtr ) - CtrlPtr = senderQ->smResultInit; - - DPRINT("\tfrom queue %04x, smResult %08x\n", queue->hSendingTask, (unsigned)CtrlPtr ); - - if( !(queue->hSendingTask = senderQ->hPrevSendingTask) ) - QUEUE_ClearWakeBit( queue, QS_SENDMESSAGE ); - - QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE ); - - queue->smResultCurrent = CtrlPtr; -// while( senderQ->wakeBits & QS_SMRESULT ) OldYield(); - - while( senderQ->wakeBits & QS_SMRESULT ) Sleep(100); - - senderQ->SendMessageReturn = 0; - senderQ->smResult = queue->smResultCurrent; - QUEUE_SetWakeBit( senderQ, QS_SMRESULT); - - senderQ = (MESSAGEQUEUE*)GlobalLock( queue->hSendingTask); - CtrlPtr = NULL; - } - queue->InSendMessageHandle = 0; - } -} - -/*********************************************************************** - * QUEUE_AddMsg - * - * Add a message to the queue. Return FALSE if queue is full. - */ -WINBOOL QUEUE_AddMsg( HQUEUE hQueue, MSG * msg, DWORD extraInfo ) -{ - int pos; - MESSAGEQUEUE *msgQueue; - - SIGNAL_MaskAsyncEvents( TRUE ); - - if (!(msgQueue = (MESSAGEQUEUE *)GlobalLock( hQueue ))) return FALSE; - pos = msgQueue->nextFreeMessage; - - /* Check if queue is full */ - if ((pos == msgQueue->nextMessage) && (msgQueue->msgCount > 0)) - { - SIGNAL_MaskAsyncEvents( FALSE ); - DPRINT("Queue is full!\n" ); - return FALSE; - } - - /* Store message */ - msgQueue->messages[pos].msg = *msg; - msgQueue->messages[pos].extraInfo = extraInfo; - if (pos < msgQueue->queueSize-1) pos++; - else pos = 0; - msgQueue->nextFreeMessage = pos; - msgQueue->msgCount++; - - SIGNAL_MaskAsyncEvents( FALSE ); - - QUEUE_SetWakeBit( msgQueue, QS_POSTMESSAGE ); - return TRUE; -} - - -/*********************************************************************** - * QUEUE_FindMsg - * - * Find a message matching the given parameters. Return -1 if none available. - */ -int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND hwnd, int first, int last ) -{ - int i, pos = msgQueue->nextMessage; - - DPRINT("hwnd=%04x pos=%d\n", hwnd, pos ); - - if (!msgQueue->msgCount) return -1; - if (!hwnd && !first && !last) return pos; - - for (i = 0; i < msgQueue->msgCount; i++) - { - MSG * msg = &msgQueue->messages[pos].msg; - - if (!hwnd || (msg->hwnd == hwnd)) - { - if (!first && !last) return pos; - if ((msg->message >= first) && (msg->message <= last)) return pos; - } - if (pos < msgQueue->queueSize-1) pos++; - else pos = 0; - } - return -1; -} - - -/*********************************************************************** - * QUEUE_RemoveMsg - * - * Remove a message from the queue (pos must be a valid position). - */ -void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, int pos ) -{ - SIGNAL_MaskAsyncEvents( TRUE ); - - if (pos >= msgQueue->nextMessage) - { - for ( ; pos > msgQueue->nextMessage; pos--) - msgQueue->messages[pos] = msgQueue->messages[pos-1]; - msgQueue->nextMessage++; - if (msgQueue->nextMessage >= msgQueue->queueSize) - msgQueue->nextMessage = 0; - } - else - { - for ( ; pos < msgQueue->nextFreeMessage; pos++) - msgQueue->messages[pos] = msgQueue->messages[pos+1]; - if (msgQueue->nextFreeMessage) msgQueue->nextFreeMessage--; - else msgQueue->nextFreeMessage = msgQueue->queueSize-1; - } - msgQueue->msgCount--; - if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE; - - SIGNAL_MaskAsyncEvents( FALSE ); -} - - -/*********************************************************************** - * QUEUE_WakeSomeone - * - * Wake a queue upon reception of a hardware event. - */ -static void QUEUE_WakeSomeone( UINT message ) -{ - WND* wndPtr = NULL; - WORD wakeBit; - HWND hwnd; - MESSAGEQUEUE *queue = pCursorQueue; - - if( (message >= WM_KEYFIRST) && (message <= WM_KEYLAST) ) - { - wakeBit = QS_KEY; - if( pActiveQueue ) queue = pActiveQueue; - } - else - { - wakeBit = (message == WM_MOUSEMOVE) ? QS_MOUSEMOVE : QS_MOUSEBUTTON; - if( (hwnd = GetCapture()) ) - if( (wndPtr = WIN_FindWndPtr( hwnd )) ) - queue = (MESSAGEQUEUE *)GlobalLock( wndPtr->hmemTaskQ ); - } - - if( (hwnd = GetSysModalWindow()) ) - if( (wndPtr = WIN_FindWndPtr( hwnd )) ) - queue = (MESSAGEQUEUE *)GlobalLock( wndPtr->hmemTaskQ ); - - if( !queue ) - { - queue = GlobalLock( hFirstQueue ); - while( queue ) - { - if (queue->wakeMask & wakeBit) break; - queue = GlobalLock( queue->next ); - } - if( !queue ) - { - DPRINT( "couldn't find queue\n"); - return; - } - } - - QUEUE_SetWakeBit( queue, wakeBit ); -} - - -/*********************************************************************** - * hardware_event - * - * Add an event to the system message queue. - * Note: the position is relative to the desktop window. - */ -void hardware_event( WORD message, WORD wParam, LONG lParam, - int xPos, int yPos, DWORD time, DWORD extraInfo ) -{ - MSG *msg; - int pos; - - if (!sysMsgQueue) return; - pos = sysMsgQueue->nextFreeMessage; - - /* Merge with previous event if possible */ - - if ((message == WM_MOUSEMOVE) && sysMsgQueue->msgCount) - { - if (pos > 0) pos--; - else pos = sysMsgQueue->queueSize - 1; - msg = &sysMsgQueue->messages[pos].msg; - if ((msg->message == message) && (msg->wParam == wParam)) - sysMsgQueue->msgCount--; /* Merge events */ - else - pos = sysMsgQueue->nextFreeMessage; /* Don't merge */ - } - - /* Check if queue is full */ - - if ((pos == sysMsgQueue->nextMessage) && sysMsgQueue->msgCount) - { - /* Queue is full, beep (but not on every mouse motion...) */ - if (message != WM_MOUSEMOVE) MessageBeep(0); - return; - } - - /* Store message */ - - msg = &sysMsgQueue->messages[pos].msg; - msg->hwnd = 0; - msg->message = message; - msg->wParam = wParam; - msg->lParam = lParam; - msg->time = time; - msg->pt.x = xPos & 0xffff; - msg->pt.y = yPos & 0xffff; - sysMsgQueue->messages[pos].extraInfo = extraInfo; - if (pos < sysMsgQueue->queueSize - 1) pos++; - else pos = 0; - sysMsgQueue->nextFreeMessage = pos; - sysMsgQueue->msgCount++; - QUEUE_WakeSomeone( message ); -} - - -/*********************************************************************** - * QUEUE_GetQueueTask - */ -HTASK QUEUE_GetQueueTask( HQUEUE hQueue ) -{ - MESSAGEQUEUE *queue = GlobalLock( hQueue ); - return (queue) ? queue->hTask : 0 ; -} - - -/*********************************************************************** - * QUEUE_IncPaintCount - */ -void QUEUE_IncPaintCount( HQUEUE hQueue ) -{ - MESSAGEQUEUE *queue; - - if (!(queue = (MESSAGEQUEUE *)GlobalLock( hQueue ))) return; - queue->wPaintCount++; - QUEUE_SetWakeBit( queue, QS_PAINT ); -} - - -/*********************************************************************** - * QUEUE_DecPaintCount - */ -void QUEUE_DecPaintCount( HQUEUE hQueue ) -{ - MESSAGEQUEUE *queue; - - if (!(queue = (MESSAGEQUEUE *)GlobalLock( hQueue ))) return; - queue->wPaintCount--; - if (!queue->wPaintCount) queue->wakeBits &= ~QS_PAINT; -} - - -/*********************************************************************** - * QUEUE_IncTimerCount - */ -void QUEUE_IncTimerCount( HQUEUE hQueue ) -{ - MESSAGEQUEUE *queue; - - if (!(queue = (MESSAGEQUEUE *)GlobalLock( hQueue ))) return; - queue->wTimerCount++; - QUEUE_SetWakeBit( queue, QS_TIMER ); -} - - -/*********************************************************************** - * QUEUE_DecTimerCount - */ -void QUEUE_DecTimerCount( HQUEUE hQueue ) -{ - MESSAGEQUEUE *queue; - - if (!(queue = (MESSAGEQUEUE *)GlobalLock( hQueue ))) return; - queue->wTimerCount--; - if (!queue->wTimerCount) queue->wakeBits &= ~QS_TIMER; -} - - diff --git a/reactos/lib/user32/internal/region.c b/reactos/lib/user32/internal/region.c deleted file mode 100644 index fc16830c96b..00000000000 --- a/reactos/lib/user32/internal/region.c +++ /dev/null @@ -1,4 +0,0 @@ -#include - - - diff --git a/reactos/lib/user32/internal/scroll.c b/reactos/lib/user32/internal/scroll.c deleted file mode 100644 index c3224f140b7..00000000000 --- a/reactos/lib/user32/internal/scroll.c +++ /dev/null @@ -1,1097 +0,0 @@ -/* - * Scrollbar control - * - * Copyright 1993 Martin Ayotte - * Copyright 1994, 1996 Alexandre Julliard - */ - -#include -#include -#include -#include -#include -#include -#include - -#define MAKEINTRESOURCEA(x) "x" - -static HBITMAP hUpArrow = 0; -static HBITMAP hDnArrow = 0; -static HBITMAP hLfArrow = 0; -static HBITMAP hRgArrow = 0; -static HBITMAP hUpArrowD = 0; -static HBITMAP hDnArrowD = 0; -static HBITMAP hLfArrowD = 0; -static HBITMAP hRgArrowD = 0; -static HBITMAP hUpArrowI = 0; -static HBITMAP hDnArrowI = 0; -static HBITMAP hLfArrowI = 0; -static HBITMAP hRgArrowI = 0; - -#define TOP_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_UP) ? hUpArrowI : ((pressed) ? hUpArrowD:hUpArrow)) -#define BOTTOM_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_DOWN) ? hDnArrowI : ((pressed) ? hDnArrowD:hDnArrow)) -#define LEFT_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_LEFT) ? hLfArrowI : ((pressed) ? hLfArrowD:hLfArrow)) -#define RIGHT_ARROW(flags,pressed) \ - (((flags)&ESB_DISABLE_RIGHT) ? hRgArrowI : ((pressed) ? hRgArrowD:hRgArrow)) - - - /* Minimum size of the rectangle between the arrows */ -#define SCROLL_MIN_RECT 4 - - /* Minimum size of the thumb in pixels */ -#define SCROLL_MIN_THUMB 6 - - /* Overlap between arrows and thumb */ -#define SCROLL_ARROW_THUMB_OVERLAP 1 - - /* Delay (in ms) before first repetition when holding the button down */ -#define SCROLL_FIRST_DELAY 200 - - /* Delay (in ms) between scroll repetitions */ -#define SCROLL_REPEAT_DELAY 50 - - /* Scroll timer id */ -#define SCROLL_TIMER 0 - - /* Scroll-bar hit testing */ -enum SCROLL_HITTEST -{ - SCROLL_NOWHERE, /* Outside the scroll bar */ - SCROLL_TOP_ARROW, /* Top or left arrow */ - SCROLL_TOP_RECT, /* Rectangle between the top arrow and the thumb */ - SCROLL_THUMB, /* Thumb rectangle */ - SCROLL_BOTTOM_RECT, /* Rectangle between the thumb and the bottom arrow */ - SCROLL_BOTTOM_ARROW /* Bottom or right arrow */ -}; - - /* What to do after SCROLL_SetScrollInfo() */ -#define SA_SSI_HIDE 0x0001 -#define SA_SSI_SHOW 0x0002 -#define SA_SSI_REFRESH 0x0004 -#define SA_SSI_REPAINT_ARROWS 0x0008 - - /* Thumb-tracking info */ -static HWND SCROLL_TrackingWin = 0; -static INT SCROLL_TrackingBar = 0; -static INT SCROLL_TrackingPos = 0; -static INT SCROLL_TrackingVal = 0; - /* Hit test code of the last button-down event */ -static enum SCROLL_HITTEST SCROLL_trackHitTest; -static WINBOOL SCROLL_trackVertical; - - /* Is the moving thumb being displayed? */ -static WINBOOL SCROLL_MovingThumb = FALSE; - - /* Local functions */ -static WINBOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, - WINBOOL fShowH, WINBOOL fShowV ); -INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, - const SCROLLINFO *info, INT *action ); - -/*********************************************************************** - * SCROLL_LoadBitmaps - */ -static void SCROLL_LoadBitmaps(void) -{ - hUpArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROW) ); - hDnArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROW) ); - hLfArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROW) ); - hRgArrow = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROW) ); - hUpArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWD) ); - hDnArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWD) ); - hLfArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWD) ); - hRgArrowD = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWD) ); - hUpArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_UPARROWI) ); - hDnArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_DNARROWI) ); - hLfArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_LFARROWI) ); - hRgArrowI = LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RGARROWI) ); -} - - -/*********************************************************************** - * SCROLL_GetPtrScrollInfo - */ -static SCROLLBAR_INFO *SCROLL_GetPtrScrollInfo( WND* wndPtr, INT nBar ) -{ - SCROLLBAR_INFO *infoPtr; - - if (!wndPtr) return NULL; - switch(nBar) - { - case SB_HORZ: infoPtr = (SCROLLBAR_INFO *)wndPtr->pHScroll; break; - case SB_VERT: infoPtr = (SCROLLBAR_INFO *)wndPtr->pVScroll; break; - case SB_CTL: infoPtr = (SCROLLBAR_INFO *)wndPtr->wExtra; break; - default: return NULL; - } - - if (!infoPtr) /* Create the info structure if needed */ - { - if ((infoPtr = HeapAlloc( GetProcessHeap(), 0, sizeof(SCROLLBAR_INFO) ))) - { - infoPtr->MinVal = infoPtr->CurVal = infoPtr->Page = 0; - infoPtr->MaxVal = 100; - infoPtr->flags = ESB_ENABLE_BOTH; - if (nBar == SB_HORZ) wndPtr->pHScroll = infoPtr; - else wndPtr->pVScroll = infoPtr; - } - if (!hUpArrow) SCROLL_LoadBitmaps(); - } - return infoPtr; -} - - -/*********************************************************************** - * SCROLL_GetScrollInfo - */ -static SCROLLBAR_INFO *SCROLL_GetScrollInfo( HWND hwnd, INT nBar ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - return SCROLL_GetPtrScrollInfo( wndPtr, nBar ); -} - - -/*********************************************************************** - * SCROLL_GetScrollBarRect - * - * Compute the scroll bar rectangle, in drawing coordinates (i.e. client - * coords for SB_CTL, window coords for SB_VERT and SB_HORZ). - * 'arrowSize' returns the width or height of an arrow (depending on - * the orientation of the scrollbar), 'thumbSize' returns the size of - * the thumb, and 'thumbPos' returns the position of the thumb - * relative to the left or to the top. - * Return TRUE if the scrollbar is vertical, FALSE if horizontal. - */ -static WINBOOL SCROLL_GetScrollBarRect( HWND hwnd, INT nBar, RECT *lprect, - INT *arrowSize, INT *thumbSize, - INT *thumbPos ) -{ - INT pixels; - WINBOOL vertical; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - switch(nBar) - { - case SB_HORZ: - lprect->left = wndPtr->rectClient.left - wndPtr->rectWindow.left; - lprect->top = wndPtr->rectClient.bottom - wndPtr->rectWindow.top; - lprect->right = wndPtr->rectClient.right - wndPtr->rectWindow.left; - lprect->bottom = lprect->top + SYSMETRICS_CYHSCROLL; - if(wndPtr->dwStyle & WS_BORDER) { - lprect->left--; - lprect->right++; - } else if(wndPtr->dwStyle & WS_VSCROLL) - lprect->right++; - vertical = FALSE; - break; - - case SB_VERT: - lprect->left = wndPtr->rectClient.right - wndPtr->rectWindow.left; - lprect->top = wndPtr->rectClient.top - wndPtr->rectWindow.top; - lprect->right = lprect->left + SYSMETRICS_CXVSCROLL; - lprect->bottom = wndPtr->rectClient.bottom - wndPtr->rectWindow.top; - if(wndPtr->dwStyle & WS_BORDER) { - lprect->top--; - lprect->bottom++; - } else if(wndPtr->dwStyle & WS_HSCROLL) - lprect->bottom++; - vertical = TRUE; - break; - - case SB_CTL: - GetClientRect( hwnd, lprect ); - vertical = ((wndPtr->dwStyle & SBS_VERT) != 0); - break; - - default: - return FALSE; - } - - if (vertical) pixels = lprect->bottom - lprect->top; - else pixels = lprect->right - lprect->left; - - if (pixels <= 2*SYSMETRICS_CXVSCROLL + SCROLL_MIN_RECT) - { - if (pixels > SCROLL_MIN_RECT) - *arrowSize = (pixels - SCROLL_MIN_RECT) / 2; - else - *arrowSize = 0; - *thumbPos = *thumbSize = 0; - } - else - { - SCROLLBAR_INFO *info = SCROLL_GetPtrScrollInfo( wndPtr, nBar ); - - *arrowSize = SYSMETRICS_CXVSCROLL; - pixels -= (2 * (SYSMETRICS_CXVSCROLL - SCROLL_ARROW_THUMB_OVERLAP)); - - if (info->Page) - { - *thumbSize = pixels * info->Page / (info->MaxVal-info->MinVal+1); - if (*thumbSize < SCROLL_MIN_THUMB) *thumbSize = SCROLL_MIN_THUMB; - } - else *thumbSize = SYSMETRICS_CXVSCROLL; - - if (((pixels -= *thumbSize ) < 0) || - ((info->flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH)) - { - /* Rectangle too small or scrollbar disabled -> no thumb */ - *thumbPos = *thumbSize = 0; - } - else - { - INT maxVal = info->MaxVal - MAX( info->Page-1, 0 ); - if (info->MinVal >= maxVal) - *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - else - *thumbPos = *arrowSize - SCROLL_ARROW_THUMB_OVERLAP - + pixels * (info->CurVal-info->MinVal) / (maxVal - info->MinVal); - } - } - return vertical; -} - - -/*********************************************************************** - * SCROLL_GetThumbVal - * - * Compute the current scroll position based on the thumb position in pixels - * from the top of the scroll-bar. - */ -static UINT SCROLL_GetThumbVal( SCROLLBAR_INFO *infoPtr, RECT *rect, - WINBOOL vertical, INT pos ) -{ - INT thumbSize; - INT pixels = vertical ? rect->bottom-rect->top : rect->right-rect->left; - - if ((pixels -= 2*(SYSMETRICS_CXVSCROLL - SCROLL_ARROW_THUMB_OVERLAP)) <= 0) - return infoPtr->MinVal; - - if (infoPtr->Page) - { - thumbSize = pixels * infoPtr->Page/(infoPtr->MaxVal-infoPtr->MinVal+1); - if (thumbSize < SCROLL_MIN_THUMB) thumbSize = SCROLL_MIN_THUMB; - } - else thumbSize = SYSMETRICS_CXVSCROLL; - - if ((pixels -= thumbSize) <= 0) return infoPtr->MinVal; - - pos = MAX( 0, pos - (SYSMETRICS_CXVSCROLL - SCROLL_ARROW_THUMB_OVERLAP) ); - if (pos > pixels) pos = pixels; - - if (!infoPtr->Page) pos *= infoPtr->MaxVal - infoPtr->MinVal; - else pos *= infoPtr->MaxVal - infoPtr->MinVal - infoPtr->Page + 1; - return infoPtr->MinVal + ((pos + pixels / 2) / pixels); -} - -/*********************************************************************** - * SCROLL_PtInRectEx - */ -static WINBOOL SCROLL_PtInRectEx( LPRECT lpRect, POINT pt, WINBOOL vertical ) -{ - RECT rect = *lpRect; - - if (vertical) - { - rect.left -= lpRect->right - lpRect->left; - rect.right += lpRect->right - lpRect->left; - } - else - { - rect.top -= lpRect->bottom - lpRect->top; - rect.bottom += lpRect->bottom - lpRect->top; - } - return PtInRect( &rect, pt ); -} - -/*********************************************************************** - * SCROLL_ClipPos - */ -static POINT SCROLL_ClipPos( LPRECT lpRect, POINT pt ) -{ - if( pt.x < lpRect->left ) - pt.x = lpRect->left; - else - if( pt.x > lpRect->right ) - pt.x = lpRect->right; - - if( pt.y < lpRect->top ) - pt.y = lpRect->top; - else - if( pt.y > lpRect->bottom ) - pt.y = lpRect->bottom; - - return pt; -} - - -/*********************************************************************** - * SCROLL_HitTest - * - * Scroll-bar hit testing (don't confuse this with WM_NCHITTEST!). - */ -static enum SCROLL_HITTEST SCROLL_HitTest( HWND hwnd, INT nBar, - POINT pt, WINBOOL bDragging ) -{ - INT arrowSize, thumbSize, thumbPos; - RECT rect; - - WINBOOL vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, - &arrowSize, &thumbSize, &thumbPos ); - - if ( (bDragging && !SCROLL_PtInRectEx( &rect, pt, vertical )) || - (!PtInRect( &rect, pt )) ) return SCROLL_NOWHERE; - - if (vertical) - { - if (pt.y < rect.top + arrowSize) return SCROLL_TOP_ARROW; - if (pt.y >= rect.bottom - arrowSize) return SCROLL_BOTTOM_ARROW; - if (!thumbPos) return SCROLL_TOP_RECT; - pt.y -= rect.top; - if (pt.y < thumbPos) return SCROLL_TOP_RECT; - if (pt.y >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT; - } - else /* horizontal */ - { - if (pt.x < rect.left + arrowSize) return SCROLL_TOP_ARROW; - if (pt.x >= rect.right - arrowSize) return SCROLL_BOTTOM_ARROW; - if (!thumbPos) return SCROLL_TOP_RECT; - pt.x -= rect.left; - if (pt.x < thumbPos) return SCROLL_TOP_RECT; - if (pt.x >= thumbPos + thumbSize) return SCROLL_BOTTOM_RECT; - } - return SCROLL_THUMB; -} - - -/*********************************************************************** - * SCROLL_DrawArrows - * - * Draw the scroll bar arrows. - */ -static void SCROLL_DrawArrows( HDC hdc, SCROLLBAR_INFO *infoPtr, - RECT *rect, INT arrowSize, WINBOOL vertical, - WINBOOL top_pressed, WINBOOL bottom_pressed ) -{ - HDC hdcMem = CreateCompatibleDC( hdc ); - HBITMAP hbmpPrev = SelectObject( hdcMem, vertical ? - TOP_ARROW(infoPtr->flags, top_pressed) - : LEFT_ARROW(infoPtr->flags, top_pressed)); - - SetStretchBltMode( hdc, STRETCH_DELETESCANS ); - StretchBlt( hdc, rect->left, rect->top, - vertical ? rect->right-rect->left : arrowSize, - vertical ? arrowSize : rect->bottom-rect->top, - hdcMem, 0, 0, - SYSMETRICS_CXVSCROLL, SYSMETRICS_CYHSCROLL, - SRCCOPY ); - - SelectObject( hdcMem, vertical ? - BOTTOM_ARROW( infoPtr->flags, bottom_pressed ) - : RIGHT_ARROW( infoPtr->flags, bottom_pressed ) ); - if (vertical) - StretchBlt( hdc, rect->left, rect->bottom - arrowSize, - rect->right - rect->left, arrowSize, - hdcMem, 0, 0, - SYSMETRICS_CXVSCROLL, SYSMETRICS_CYHSCROLL, - SRCCOPY ); - else - StretchBlt( hdc, rect->right - arrowSize, rect->top, - arrowSize, rect->bottom - rect->top, - hdcMem, 0, 0, - SYSMETRICS_CXVSCROLL, SYSMETRICS_CYHSCROLL, - SRCCOPY ); - SelectObject( hdcMem, hbmpPrev ); - DeleteDC( hdcMem ); -} - - -/*********************************************************************** - * SCROLL_DrawMovingThumb - * - * Draw the moving thumb rectangle. - */ -static void SCROLL_DrawMovingThumb( HDC hdc, RECT *rect, WINBOOL vertical, - INT arrowSize, INT thumbSize ) -{ - RECT r = *rect; - if (vertical) - { - r.top += SCROLL_TrackingPos; - if (r.top < rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - r.top = rect->top + arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - if (r.top + thumbSize > - rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)) - r.top = rect->bottom - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - - thumbSize; - r.bottom = r.top + thumbSize; - } - else - { - r.left += SCROLL_TrackingPos; - if (r.left < rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - r.left = rect->left + arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - if (r.left + thumbSize > - rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP)) - r.left = rect->right - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - - thumbSize; - r.right = r.left + thumbSize; - } - DrawFocusRect( hdc, &r ); - SCROLL_MovingThumb = !SCROLL_MovingThumb; -} - - -/*********************************************************************** - * SCROLL_DrawInterior - * - * Draw the scroll bar interior (everything except the arrows). - */ -static void SCROLL_DrawInterior( HWND hwnd, HDC hdc, INT nBar, - RECT *rect, INT arrowSize, - INT thumbSize, INT thumbPos, - UINT flags, WINBOOL vertical, - WINBOOL top_selected, WINBOOL bottom_selected ) -{ - RECT r; - - /* Select the correct brush and pen */ - - - - SelectObject( hdc, GetSysColorBrush(COLOR_WINDOWFRAME) ); - if ((flags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH) - { - /* This ought to be the color of the parent window */ - SelectObject( hdc, GetSysColorBrush(COLOR_WINDOW) ); - } - else - { - if (nBar == SB_CTL) /* Only scrollbar controls send WM_CTLCOLOR */ - { - HBRUSH hbrush = SendMessageA(GetParent(hwnd), - WM_CTLCOLORSCROLLBAR, (WPARAM)hdc, (LPARAM)hwnd ); - SelectObject( hdc, hbrush ); - } - else SelectObject( hdc, GetSysColorBrush(COLOR_SCROLLBAR) ); - } - - /* Calculate the scroll rectangle */ - - r = *rect; - if (vertical) - { - r.top += arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - r.bottom -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - } - else - { - r.left += arrowSize - SCROLL_ARROW_THUMB_OVERLAP; - r.right -= (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - } - - /* Draw the scroll bar frame */ - - Rectangle( hdc, r.left, r.top, r.right, r.bottom ); - - /* Draw the scroll rectangles and thumb */ - - if (!thumbPos) /* No thumb to draw */ - { - PatBlt( hdc, r.left+1, r.top+1, r.right - r.left - 2, - r.bottom - r.top - 2, PATCOPY ); - return; - } - - if (vertical) - { - PatBlt( hdc, r.left + 1, r.top + 1, - r.right - r.left - 2, - thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - 1, - top_selected ? 0x0f0000 : PATCOPY ); - r.top += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - PatBlt( hdc, r.left + 1, r.top + thumbSize, - r.right - r.left - 2, - r.bottom - r.top - thumbSize - 1, - bottom_selected ? 0x0f0000 : PATCOPY ); - r.bottom = r.top + thumbSize; - } - else /* horizontal */ - { - PatBlt( hdc, r.left + 1, r.top + 1, - thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP) - 1, - r.bottom - r.top - 2, - top_selected ? 0x0f0000 : PATCOPY ); - r.left += thumbPos - (arrowSize - SCROLL_ARROW_THUMB_OVERLAP); - PatBlt( hdc, r.left + thumbSize, r.top + 1, - r.right - r.left - thumbSize - 1, - r.bottom - r.top - 2, - bottom_selected ? 0x0f0000 : PATCOPY ); - r.right = r.left + thumbSize; - } - - /* Draw the thumb */ - - SelectObject( hdc, GetSysColorBrush(COLOR_BTNFACE) ); - Rectangle( hdc, r.left, r.top, r.right, r.bottom ); - r.top++, r.left++; - DrawEdge( hdc, &r, EDGE_RAISED, BF_RECT ); - if (SCROLL_MovingThumb && - (SCROLL_TrackingWin == hwnd) && - (SCROLL_TrackingBar == nBar)) - { - SCROLL_DrawMovingThumb( hdc, rect, vertical, arrowSize, thumbSize ); - SCROLL_MovingThumb = TRUE; - } -} - - -/*********************************************************************** - * SCROLL_DrawScrollBar - * - * Redraw the whole scrollbar. - */ -void SCROLL_DrawScrollBar( HWND hwnd, HDC hdc, INT nBar, - WINBOOL arrows, WINBOOL interior ) -{ - INT arrowSize, thumbSize, thumbPos; - RECT rect; - WINBOOL vertical; - WND *wndPtr = WIN_FindWndPtr( hwnd ); - SCROLLBAR_INFO *infoPtr = SCROLL_GetPtrScrollInfo( wndPtr, nBar ); - - if (!wndPtr || !infoPtr || - ((nBar == SB_VERT) && !(wndPtr->dwStyle & WS_VSCROLL)) || - ((nBar == SB_HORZ) && !(wndPtr->dwStyle & WS_HSCROLL))) return; - if (!WIN_IsWindowDrawable( wndPtr, FALSE )) return; - - vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, - &arrowSize, &thumbSize, &thumbPos ); - - /* Draw the arrows */ - - if (arrows && arrowSize) - { - if( vertical == SCROLL_trackVertical && GetCapture() == hwnd ) - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - (SCROLL_trackHitTest == SCROLL_TOP_ARROW), - (SCROLL_trackHitTest == SCROLL_BOTTOM_ARROW) ); - else - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - FALSE, FALSE ); - } - if( interior ) - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, FALSE, FALSE ); -} - - -/*********************************************************************** - * SCROLL_RefreshScrollBar - * - * Repaint the scroll bar interior after a SetScrollRange() or - * SetScrollPos() call. - */ -static void SCROLL_RefreshScrollBar( HWND hwnd, INT nBar, - WINBOOL arrows, WINBOOL interior ) -{ - HDC hdc = GetDCEx( hwnd, 0, - DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW) ); - if (!hdc) return; - - SCROLL_DrawScrollBar( hwnd, hdc, nBar, arrows, interior ); - ReleaseDC( hwnd, hdc ); -} - - -/*********************************************************************** - * SCROLL_HandleKbdEvent - * - * Handle a keyboard event (only for SB_CTL scrollbars). - */ -void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - WPARAM msg; - - switch(wParam) - { - case VK_PRIOR: msg = SB_PAGEUP; break; - case VK_NEXT: msg = SB_PAGEDOWN; break; - case VK_HOME: msg = SB_TOP; break; - case VK_END: msg = SB_BOTTOM; break; - case VK_UP: msg = SB_LINEUP; break; - case VK_DOWN: msg = SB_LINEDOWN; break; - default: - return; - } - SendMessageA( GetParent(hwnd), - (wndPtr->dwStyle & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL, - msg, (LPARAM)hwnd ); -} - - -/*********************************************************************** - * SCROLL_HandleScrollEvent - * - * Handle a mouse or timer event for the scrollbar. - * 'pt' is the location of the mouse event in client (for SB_CTL) or - * windows coordinates. - */ -void SCROLL_HandleScrollEvent( HWND hwnd, INT nBar, UINT msg, POINT pt) -{ - /* Previous mouse position for timer events */ - static POINT prevPt; - /* Thumb position when tracking started. */ - static UINT trackThumbPos; - /* Position in the scroll-bar of the last button-down event. */ - static INT lastClickPos; - /* Position in the scroll-bar of the last mouse event. */ - static INT lastMousePos; - - enum SCROLL_HITTEST hittest; - HWND hwndOwner, hwndCtl; - WINBOOL vertical; - INT arrowSize, thumbSize, thumbPos; - RECT rect; - HDC hdc; - - SCROLLBAR_INFO *infoPtr = SCROLL_GetScrollInfo( hwnd, nBar ); - if (!infoPtr) return; - if ((SCROLL_trackHitTest == SCROLL_NOWHERE) && (msg != WM_LBUTTONDOWN)) - return; - - hdc = GetDCEx( hwnd, 0, DCX_CACHE | ((nBar == SB_CTL) ? 0 : DCX_WINDOW)); - vertical = SCROLL_GetScrollBarRect( hwnd, nBar, &rect, - &arrowSize, &thumbSize, &thumbPos ); - hwndOwner = (nBar == SB_CTL) ? GetParent(hwnd) : hwnd; - hwndCtl = (nBar == SB_CTL) ? hwnd : 0; - - switch(msg) - { - case WM_LBUTTONDOWN: /* Initialise mouse tracking */ - SCROLL_trackVertical = vertical; - SCROLL_trackHitTest = hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE ); - lastClickPos = vertical ? (pt.y - rect.top) : (pt.x - rect.left); - lastMousePos = lastClickPos; - trackThumbPos = thumbPos; - prevPt = pt; - SetCapture( hwnd ); - if (nBar == SB_CTL) SetFocus( hwnd ); - break; - - case WM_MOUSEMOVE: - hittest = SCROLL_HitTest( hwnd, nBar, pt, TRUE ); - prevPt = pt; - break; - - case WM_LBUTTONUP: - hittest = SCROLL_NOWHERE; - ReleaseCapture(); - break; - - case WM_SYSTIMER: - pt = prevPt; - hittest = SCROLL_HitTest( hwnd, nBar, pt, FALSE ); - break; - - default: - return; /* Should never happen */ - } - - DPRINT( "Event: hwnd=%04x bar=%d msg=%x pt=%d,%d hit=%d\n", - hwnd, nBar, msg, pt.x, pt.y, hittest ); - - switch(SCROLL_trackHitTest) - { - case SCROLL_NOWHERE: /* No tracking in progress */ - break; - - case SCROLL_TOP_ARROW: - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - (hittest == SCROLL_trackHitTest), FALSE ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_LINEUP, (LPARAM)hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - - case SCROLL_TOP_RECT: - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, - (hittest == SCROLL_trackHitTest), FALSE ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_PAGEUP, (LPARAM)hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - - case SCROLL_THUMB: - if (msg == WM_LBUTTONDOWN) - { - SCROLL_TrackingWin = hwnd; - SCROLL_TrackingBar = nBar; - SCROLL_TrackingPos = trackThumbPos + lastMousePos - lastClickPos; - SCROLL_DrawMovingThumb(hdc, &rect, vertical, arrowSize, thumbSize); - } - else if (msg == WM_LBUTTONUP) - { - SCROLL_TrackingWin = 0; - SCROLL_MovingThumb = FALSE; - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, - FALSE, FALSE ); - } - else /* WM_MOUSEMOVE */ - { - UINT pos; - - if (!SCROLL_PtInRectEx( &rect, pt, vertical )) pos = lastClickPos; - else - { - pt = SCROLL_ClipPos( &rect, pt ); - pos = vertical ? (pt.y - rect.top) : (pt.x - rect.left); - } - if (pos != lastMousePos) - { - SCROLL_DrawMovingThumb( hdc, &rect, vertical, - arrowSize, thumbSize ); - lastMousePos = pos; - SCROLL_TrackingPos = trackThumbPos + pos - lastClickPos; - SCROLL_TrackingVal = SCROLL_GetThumbVal( infoPtr, &rect, - vertical, - SCROLL_TrackingPos ); - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - MAKEWPARAM( SB_THUMBTRACK, SCROLL_TrackingVal), - (LPARAM)hwndCtl ); - SCROLL_DrawMovingThumb( hdc, &rect, vertical, - arrowSize, thumbSize ); - } - } - break; - - case SCROLL_BOTTOM_RECT: - SCROLL_DrawInterior( hwnd, hdc, nBar, &rect, arrowSize, thumbSize, - thumbPos, infoPtr->flags, vertical, - FALSE, (hittest == SCROLL_trackHitTest) ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_PAGEDOWN, (LPARAM)hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - - case SCROLL_BOTTOM_ARROW: - SCROLL_DrawArrows( hdc, infoPtr, &rect, arrowSize, vertical, - FALSE, (hittest == SCROLL_trackHitTest) ); - if (hittest == SCROLL_trackHitTest) - { - if ((msg == WM_LBUTTONDOWN) || (msg == WM_SYSTIMER)) - { - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_LINEDOWN, (LPARAM)hwndCtl ); - SetTimer( hwnd, SCROLL_TIMER, (msg == WM_LBUTTONDOWN) ? - SCROLL_FIRST_DELAY : SCROLL_REPEAT_DELAY, - (TIMERPROC)0 ); - } - } - else KillTimer( hwnd, SCROLL_TIMER ); - break; - } - - if (msg == WM_LBUTTONUP) - { - hittest = SCROLL_trackHitTest; - SCROLL_trackHitTest = SCROLL_NOWHERE; /* Terminate tracking */ - - if (hittest == SCROLL_THUMB) - { - UINT val = SCROLL_GetThumbVal( infoPtr, &rect, vertical, - trackThumbPos + lastMousePos - lastClickPos ); - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - MAKEWPARAM( SB_THUMBPOSITION, val ), (LPARAM)hwndCtl ); - } - else - SendMessageA( hwndOwner, vertical ? WM_VSCROLL : WM_HSCROLL, - SB_ENDSCROLL, (LPARAM)hwndCtl ); - } - - ReleaseDC( hwnd, hdc ); -} - - -/************************************************************************* - * SCROLL_ShowScrollBar() - * - * Back-end for ShowScrollBar(). Returns FALSE if no action was taken. - * NOTE: fShowV/fShowH must be zero when nBar is SB_HORZ/SB_VERT. - */ -WINBOOL SCROLL_ShowScrollBar( HWND hwnd, INT nBar, - WINBOOL fShowH, WINBOOL fShowV ) -{ - WND *wndPtr = WIN_FindWndPtr( hwnd ); - - if (!wndPtr) return FALSE; - DPRINT( "hwnd=%04x bar=%d horz=%d, vert=%d\n", - hwnd, nBar, fShowH, fShowV ); - - switch(nBar) - { - case SB_CTL: - ShowWindow( hwnd, fShowH ? SW_SHOW : SW_HIDE ); - return TRUE; - - case SB_BOTH: - case SB_HORZ: - if (fShowH) - { - fShowH = !(wndPtr->dwStyle & WS_HSCROLL); - wndPtr->dwStyle |= WS_HSCROLL; - } - else /* hide it */ - { - fShowH = (wndPtr->dwStyle & WS_HSCROLL); - wndPtr->dwStyle &= ~WS_HSCROLL; - } - if( nBar == SB_HORZ ) break; - /* fall through */ - - case SB_VERT: - if (fShowV) - { - fShowV = !(wndPtr->dwStyle & WS_VSCROLL); - wndPtr->dwStyle |= WS_VSCROLL; - } - else /* hide it */ - { - fShowV = (wndPtr->dwStyle & WS_VSCROLL); - wndPtr->dwStyle &= ~WS_VSCROLL; - } - break; - - default: - return FALSE; /* Nothing to do! */ - } - - if( fShowH || fShowV ) /* frame has been changed, let the window redraw itself */ - { - SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE - | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED ); - return TRUE; - } - - return FALSE; /* no frame changes */ -} - -/************************************************************************* - * SCROLL_SetNCSbState - * - * Updates both scrollbars at the same time. Used by MDI CalcChildScroll(). - */ -INT SCROLL_SetNCSbState(WND* wndPtr, int vMin, int vMax, int vPos, - int hMin, int hMax, int hPos) -{ - INT vA, hA; - SCROLLINFO vInfo, hInfo; - - vInfo.cbSize = hInfo.cbSize = sizeof(SCROLLINFO); - vInfo.nMin = vMin; hInfo.nMin = hMin; - vInfo.nMax = vMax; hInfo.nMax = hMax; - vInfo.nPos = vPos; hInfo.nPos = hPos; - vInfo.fMask = hInfo.fMask = SIF_RANGE | SIF_POS; - - SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_VERT, &vInfo, &vA ); - SCROLL_SetScrollInfo( wndPtr->hwndSelf, SB_HORZ, &hInfo, &hA ); - - if( !SCROLL_ShowScrollBar( wndPtr->hwndSelf, SB_BOTH, - (hA & SA_SSI_SHOW),(vA & SA_SSI_SHOW) ) ) - { - /* SetWindowPos() wasn't called, just redraw the scrollbars if needed */ - if( vA & SA_SSI_REFRESH ) - SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_VERT, FALSE, TRUE ); - - if( hA & SA_SSI_REFRESH ) - SCROLL_RefreshScrollBar( wndPtr->hwndSelf, SB_HORZ, FALSE, TRUE ); - } - return 0; -} - -INT SCROLL_SetScrollInfo( HWND hwnd, INT nBar, - const SCROLLINFO *info, INT *action ) -{ - /* Update the scrollbar state and set action flags according to - * what has to be done graphics wise. */ - - SCROLLBAR_INFO *infoPtr; - UINT new_flags; - - //dbg_decl_str(scroll, 256); - - *action = 0; - - if (!(infoPtr = SCROLL_GetScrollInfo(hwnd, nBar))) return 0; - if (info->fMask & ~(SIF_ALL | SIF_DISABLENOSCROLL)) return 0; - if ((info->cbSize != sizeof(*info)) && - (info->cbSize != sizeof(*info)-sizeof(info->nTrackPos))) return 0; - - /* Set the page size */ - - if (info->fMask & SIF_PAGE) - { - DPRINT( " page=%d", info->nPage ); - if( infoPtr->Page != info->nPage ) - { - infoPtr->Page = info->nPage; - *action |= SA_SSI_REFRESH; - } - } - - /* Set the scroll pos */ - - if (info->fMask & SIF_POS) - { - DPRINT( " pos=%d", info->nPos ); - if( infoPtr->CurVal != info->nPos ) - { - infoPtr->CurVal = info->nPos; - *action |= SA_SSI_REFRESH; - } - } - - /* Set the scroll range */ - - if (info->fMask & SIF_RANGE) - { - DPRINT( " min=%d max=%d", info->nMin, info->nMax ); - - /* Invalid range -> range is set to (0,0) */ - if ((info->nMin > info->nMax) || - ((UINT)(info->nMax - info->nMin) >= 0x80000000)) - { - infoPtr->MinVal = 0; - infoPtr->MaxVal = 0; - } - else - { - if( infoPtr->MinVal != info->nMin || - infoPtr->MaxVal != info->nMax ) - { - *action |= SA_SSI_REFRESH; - infoPtr->MinVal = info->nMin; - infoPtr->MaxVal = info->nMax; - } - } - } - - //DPRINT("hwnd=%04x bar=%d %s\n", - // hwnd, nBar, dbg_str(scroll)); - - /* Make sure the page size is valid */ - - if (infoPtr->Page < 0) infoPtr->Page = 0; - else if (infoPtr->Page > infoPtr->MaxVal - infoPtr->MinVal + 1 ) - infoPtr->Page = infoPtr->MaxVal - infoPtr->MinVal + 1; - - /* Make sure the pos is inside the range */ - - if (infoPtr->CurVal < infoPtr->MinVal) - infoPtr->CurVal = infoPtr->MinVal; - else if (infoPtr->CurVal > infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 )) - infoPtr->CurVal = infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 ); - - DPRINT(" new values: page=%d pos=%d min=%d max=%d\n", - infoPtr->Page, infoPtr->CurVal, - infoPtr->MinVal, infoPtr->MaxVal ); - - /* Check if the scrollbar should be hidden or disabled */ - - if (info->fMask & (SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL)) - { - new_flags = infoPtr->flags; - if (infoPtr->MinVal >= infoPtr->MaxVal - MAX( infoPtr->Page-1, 0 )) - { - /* Hide or disable scroll-bar */ - if (info->fMask & SIF_DISABLENOSCROLL) - { - new_flags = ESB_DISABLE_BOTH; - *action |= SA_SSI_REFRESH; - } - else if (nBar != SB_CTL) - { - *action = SA_SSI_HIDE; - goto done; - } - } - else /* Show and enable scroll-bar */ - { - new_flags = 0; - if (nBar != SB_CTL) - *action |= SA_SSI_SHOW; - } - - if (infoPtr->flags != new_flags) /* check arrow flags */ - { - infoPtr->flags = new_flags; - *action |= SA_SSI_REPAINT_ARROWS; - } - } - -done: - /* Return current position */ - - return infoPtr->CurVal; -} - -/************************************************************************* - * SCROLL_FixCaret - */ -WINBOOL SCROLL_FixCaret(HWND hWnd, LPRECT lprc, UINT flags) -{ - HWND hCaret = CARET_GetHwnd(); - - if( hCaret ) - { - RECT rc; - CARET_GetRect( &rc ); - if( hCaret == hWnd || - (flags & SW_SCROLLCHILDREN && IsChild(hWnd, hCaret)) ) - { - POINT pt; - - pt.x = rc.left; pt.y = rc.top; - MapWindowPoints( hCaret, hWnd, (LPPOINT)&rc, 2 ); - if( IntersectRect(lprc, lprc, &rc) ) - { - HideCaret(0); - lprc->left = pt.x; lprc->top = pt.y; - return TRUE; - } - } - } - return FALSE; -} \ No newline at end of file diff --git a/reactos/lib/user32/internal/signal.c b/reactos/lib/user32/internal/signal.c deleted file mode 100644 index 413d9da6624..00000000000 --- a/reactos/lib/user32/internal/signal.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void SIGNAL_MaskAsyncEvents( WINBOOL flag ) -{ - // sigprocmask( (flag) ? SIG_BLOCK : SIG_UNBLOCK , &async_signal_set, NULL); -} \ No newline at end of file diff --git a/reactos/lib/user32/internal/text.c b/reactos/lib/user32/internal/text.c deleted file mode 100644 index 190ab6582fc..00000000000 --- a/reactos/lib/user32/internal/text.c +++ /dev/null @@ -1,720 +0,0 @@ -/* - * text functions - * - * Copyright 1993, 1994 Alexandre Julliard - * - */ - -//#include -#include -#include - - - - -int tabstop; -int tabwidth; -int spacewidth; -int prefix_offset; -/* -typedef struct { - UINT cbSize; - int iTabLength; - int iLeftMargin; - int iRightMargin; - UINT uiLengthDrawn; -} DRAWTEXTPARAMS, FAR *LPDRAWTEXTPARAMS; -*/ - -int TEXT_DrawTextEx(HDC hDC,void *strPtr,int nCount,LPRECT lpRect,UINT uFormat,LPDRAWTEXTPARAMS dtp,WINBOOL Unicode ) -{ - SIZE size; - int line[1024]; - int len, lh, count=nCount; - int prefix_x = 0; - int prefix_end = 0; - TEXTMETRIC tm; - int x = lpRect->left, y = lpRect->top; - int width = lpRect->right - lpRect->left; - int max_width = 0; - - //TRACE(text,"%s, %d , [(%d,%d),(%d,%d)]\n", - // debugstr_an (lpString, count), count, - // lpRect->left, lpRect->top, lpRect->right, lpRect->bottom); - - if (count == -1) { - if ( Unicode ) - count = lstrlenW(strPtr); - else - count = lstrlenA(strPtr); - } - if ( Unicode ) - GetTextMetricsW(hDC, &tm); - else - GetTextMetricsA(hDC, &tm); - - if (uFormat & DT_EXTERNALLEADING) - lh = tm.tmHeight + tm.tmExternalLeading; - else - lh = tm.tmHeight; - - if (uFormat & DT_TABSTOP) - tabstop = uFormat >> 8; - - - if (uFormat & DT_EXPANDTABS) - { - GetTextExtentPointA(hDC, " ", 1, &size); - spacewidth = size.cx; - if ( dtp->iTabLength == 0 ) { - GetTextExtentPointA(hDC, "o", 1, &size); - tabwidth = size.cx * tabstop; - } - else - tabwidth = tabstop * dtp->iTabLength; - - } - - if (uFormat & DT_CALCRECT) uFormat |= DT_NOCLIP; - - do - { - prefix_offset = -1; - if ( Unicode ) - strPtr = TEXT_NextLineW(hDC, strPtr, &count, (LPWSTR)line, &len, width, uFormat); - else - strPtr = TEXT_NextLineA(hDC, strPtr, &count, (LPSTR)line, &len, width, uFormat); - - if ( Unicode ) { - if (prefix_offset != -1) - { - GetTextExtentPointW(hDC, (LPWSTR)line, prefix_offset, &size); - prefix_x = size.cx; - GetTextExtentPointW(hDC, (LPWSTR)line, prefix_offset + 1, &size); - prefix_end = size.cx - 1; - } - if (!GetTextExtentPointW(hDC, (LPWSTR)line, len, &size)) - return 0; - } - else { - if (prefix_offset != -1) - { - GetTextExtentPointA(hDC, (LPSTR)line, prefix_offset, &size); - prefix_x = size.cx; - GetTextExtentPointA(hDC, (LPSTR)line, prefix_offset + 1, &size); - prefix_end = size.cx - 1; - } - if (!GetTextExtentPointA(hDC, (LPSTR)line, len, &size)) - return 0; - } - - - - if (uFormat & DT_CENTER) - x = (lpRect->left + lpRect->right - size.cx) / 2; - else if (uFormat & DT_RIGHT) - x = lpRect->right - size.cx; - - if (uFormat & DT_SINGLELINE) - { - if (uFormat & DT_VCENTER) y = lpRect->top + - (lpRect->bottom - lpRect->top) / 2 - size.cy / 2; - else if (uFormat & DT_BOTTOM) y = lpRect->bottom - size.cy; - } - if (!(uFormat & DT_CALCRECT)) - { - if ( Unicode ) { - if (!ExtTextOutW(hDC, x, y, (uFormat & DT_NOCLIP) ? 0 : ETO_CLIPPED,lpRect, (LPWSTR)line, len, NULL )) - return 0; - } - else { - if (!ExtTextOutA(hDC, x, y, (uFormat & DT_NOCLIP) ? 0 : ETO_CLIPPED,lpRect, (LPSTR)line, len, NULL )) - return 0; - } - if (prefix_offset != -1) - { - HPEN hpen = CreatePen( PS_SOLID, 1, GetTextColor(hDC) ); - HPEN oldPen = SelectObject( hDC, hpen ); - MoveToEx(hDC, x + prefix_x, y + tm.tmAscent + 1,NULL ); - LineTo(hDC, x + prefix_end + 1, y + tm.tmAscent + 1 ); - SelectObject( hDC, oldPen ); - DeleteObject( hpen ); - } - } - else if (size.cx > max_width) - max_width = size.cx; - - y += lh; - if (strPtr) - { - if (!(uFormat & DT_NOCLIP)) - { - if (y > lpRect->bottom - lh) - break; - } - } - } - while (strPtr); - if (uFormat & DT_CALCRECT) - { - lpRect->right = lpRect->left + max_width; - lpRect->bottom = y; - } - return y - lpRect->top; -} - - -LPCSTR TEXT_NextLineA( HDC hdc, LPCSTR str, INT *count, - LPSTR dest, INT *len, INT width, WORD format) -{ - /* Return next line of text from a string. - * - * hdc - handle to DC. - * str - string to parse into lines. - * count - length of str. - * dest - destination in which to return line. - * len - length of resultant line in dest in chars. - * width - maximum width of line in pixels. - * format - format type passed to DrawText. - * - * Returns pointer to next char in str after end of the line - * or NULL if end of str reached. - */ - - int i = 0, j = 0, k; - int plen = 0; - int numspaces; - SIZE size; - int lasttab = 0; - int wb_i = 0, wb_j = 0, wb_count = 0; - - while (*count) - { - switch (str[i]) - { - case CR: - case LF: - if (!(format & DT_SINGLELINE)) - { - if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF)) - { - (*count)--; - i++; - } - i++; - *len = j; - (*count)--; - return (&str[i]); - } - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointA(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - break; - - case PREFIX: - if (!(format & DT_NOPREFIX) && *count > 1) - { - if (str[++i] == PREFIX) - (*count)--; - else { - prefix_offset = j; - break; - } - } - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointA(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - break; - - case TAB: - if (format & DT_EXPANDTABS) - { - wb_i = ++i; - wb_j = j; - wb_count = *count; - - if (!GetTextExtentPointA(hdc, &dest[lasttab], j - lasttab, - &size)) - return NULL; - - numspaces = (tabwidth - size.cx) / spacewidth; - for (k = 0; k < numspaces; k++) - dest[j++] = SPACE; - plen += tabwidth - size.cx; - lasttab = wb_j + numspaces; - } - else - { - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointA(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - } - break; - - case SPACE: - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - wb_i = i; - wb_j = j - 1; - wb_count = *count; - if (!GetTextExtentPointA(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - break; - - default: - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointA(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - } - - (*count)--; - if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK)) - { - if (plen > width) - { - if (format & DT_WORDBREAK) - { - if (wb_j) - { - *len = wb_j; - *count = wb_count - 1; - return (&str[wb_i]); - } - } - else - { - *len = j; - return (&str[i]); - } - } - } - } - - *len = j; - return NULL; -} - -LPCWSTR TEXT_NextLineW( HDC hdc, LPCWSTR str, INT *count, - LPWSTR dest, INT *len, INT width, WORD format) -{ - /* Return next line of text from a string. - * - * hdc - handle to DC. - * str - string to parse into lines. - * count - length of str. - * dest - destination in which to return line. - * len - length of resultant line in dest in chars. - * width - maximum width of line in pixels. - * format - format type passed to DrawText. - * - * Returns pointer to next char in str after end of the line - * or NULL if end of str reached. - */ - - int i = 0, j = 0, k; - int plen = 0; - int numspaces; - SIZE size; - int lasttab = 0; - int wb_i = 0, wb_j = 0, wb_count = 0; - - while (*count) - { - switch (str[i]) - { - case CR: - case LF: - if (!(format & DT_SINGLELINE)) - { - if ((*count > 1) && (str[i] == CR) && (str[i+1] == LF)) - { - (*count)--; - i++; - } - i++; - *len = j; - (*count)--; - return (&str[i]); - } - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - break; - - case PREFIX: - if (!(format & DT_NOPREFIX) && *count > 1) - { - if (str[++i] == PREFIX) - (*count)--; - else { - prefix_offset = j; - break; - } - } - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - break; - - case TAB: - if (format & DT_EXPANDTABS) - { - wb_i = ++i; - wb_j = j; - wb_count = *count; - - if (!GetTextExtentPointW(hdc, &dest[lasttab], j - lasttab, - &size)) - return NULL; - - numspaces = (tabwidth - size.cx) / spacewidth; - for (k = 0; k < numspaces; k++) - dest[j++] = SPACE; - plen += tabwidth - size.cx; - lasttab = wb_j + numspaces; - } - else - { - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - } - break; - - case SPACE: - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - wb_i = i; - wb_j = j - 1; - wb_count = *count; - if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - break; - - default: - dest[j++] = str[i++]; - if (!(format & DT_NOCLIP) || !(format & DT_NOPREFIX) || - (format & DT_WORDBREAK)) - { - if (!GetTextExtentPointW(hdc, &dest[j-1], 1, &size)) - return NULL; - plen += size.cx; - } - } - - (*count)--; - if (!(format & DT_NOCLIP) || (format & DT_WORDBREAK)) - { - if (plen > width) - { - if (format & DT_WORDBREAK) - { - if (wb_j) - { - *len = wb_j; - *count = wb_count - 1; - return (&str[wb_i]); - } - } - else - { - *len = j; - return (&str[i]); - } - } - } - } - - *len = j; - return NULL; -} - -#if 0 - - -WINBOOL TEXT_GrayString(HDC hdc, HBRUSH hb, - GRAYSTRINGPROC fn, LPARAM lp, INT len, - INT x, INT y, INT cx, INT cy, WINBOOL Unicode) -{ - HBITMAP hbm, hbmsave; - HBRUSH hbsave; - HFONT hfsave; - HDC memdc = CreateCompatibleDC(hdc); - int slen = len; - WINBOOL retval = TRUE; - RECT r; - COLORREF fg, bg; - - if(!hdc) return FALSE; - - if(len == 0) - { - if ( Unicode ) - slen = lstrlenW((LPCWSTR)lp); - else - slen = lstrlenA((LPCSTR)lp); - - } - - if((cx == 0 || cy == 0) && slen != -1) - { - SIZE s; - if ( Unicode ) - GetTextExtentPointW(hdc, (LPCWSTR)lp, slen, &s); - else - GetTextExtentPointA(hdc, (LPCSTR)lp, slen, &s); - - if(cx == 0) cx = s.cx; - if(cy == 0) cy = s.cy; - } - - r.left = r.top = 0; - r.right = cx; - r.bottom = cy; - - hbm = CreateBitmap(cx, cy, 1, 1, NULL); - hbmsave = (HBITMAP)SelectObject(memdc, hbm); - FillRect(memdc, &r, (HBRUSH)GetStockObject(BLACK_BRUSH)); - SetTextColor(memdc, RGB(255, 255, 255)); - SetBkColor(memdc, RGB(0, 0, 0)); - hfsave = (HFONT)SelectObject(memdc, GetCurrentObject(hdc, OBJ_FONT)); - - if(fn) - retval = fn(memdc, lp, slen); - else { - if (Unicode ) - TextOutW(memdc, 0, 0, (LPCWSTR)lp, slen); - else - TextOutA(memdc, 0, 0, (LPCSTR)lp, slen); - } - - - SelectObject(memdc, hfsave); - -/* - * Windows doc says that the bitmap isn't grayed when len == -1 and - * the callback function returns FALSE. However, testing this on - * win95 showed otherwise... -*/ -#ifdef GRAYSTRING_USING_DOCUMENTED_BEHAVIOUR - if(retval || len != -1) -#endif - { - hbsave = (HBRUSH)SelectObject(memdc, CACHE_GetPattern55AABrush()); - PatBlt(memdc, 0, 0, cx, cy, 0x000A0329); - SelectObject(memdc, hbsave); - } - - if(hb) hbsave = (HBRUSH)SelectObject(hdc, hb); - fg = SetTextColor(hdc, RGB(0, 0, 0)); - bg = SetBkColor(hdc, RGB(255, 255, 255)); - BitBlt(hdc, x, y, cx, cy, memdc, 0, 0, 0x00E20746); - SetTextColor(hdc, fg); - SetBkColor(hdc, bg); - if(hb) SelectObject(hdc, hbsave); - - SelectObject(memdc, hbmsave); - DeleteObject(hbm); - DeleteDC(memdc); - return retval; -} - - -#endif - -/*********************************************************************** - * TEXT_TabbedTextOut - * - * Helper function for TabbedTextOut() and GetTabbedTextExtent(). - * Note: this doesn't work too well for text-alignment modes other - * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-) - */ -LONG TEXT_TabbedTextOutA( HDC hdc, INT x, INT y, LPCSTR lpstr, - INT count, INT cTabStops, const INT *lpTabPos, - INT nTabOrg, WINBOOL fDisplayText ) -{ - INT defWidth; - DWORD extent = 0; - int i, tabPos = x; - int start = x; - SIZE szSize; - - if (cTabStops == 1) - { - defWidth = lpTabPos ? *lpTabPos : 0; - cTabStops = 0; - } - else - { - TEXTMETRIC tm; - GetTextMetricsA( hdc, &tm ); - defWidth = 8 * tm.tmAveCharWidth; - } - - while (count > 0) - { - for (i = 0; i < count; i++) - if (lpstr[i] == '\t') break; - GetTextExtentPoint32A( hdc, lpstr, i, &szSize ); - extent = szSize.cx; - if (lpTabPos) - { - while ((cTabStops > 0) && - (nTabOrg + *lpTabPos <= x + LOWORD(extent))) - { - lpTabPos++; - cTabStops--; - } - } - else - { - while ((cTabStops > 0) && - (nTabOrg + *lpTabPos <= x + LOWORD(extent))) - { - lpTabPos++; - cTabStops--; - } - } - if (i == count) - tabPos = x + LOWORD(extent); - else if (cTabStops > 0) - tabPos = nTabOrg + (lpTabPos ? *lpTabPos : 0); - else - tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth; - if (fDisplayText) - { - RECT r; - SetRect( &r, x, y, tabPos, y+HIWORD(extent) ); - ExtTextOutA( hdc, x, y, - GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0, - &r, lpstr, i, NULL ); - } - x = tabPos; - count -= i+1; - lpstr += i+1; - } - return MAKELONG(tabPos - start, HIWORD(extent)); -} - -/*********************************************************************** - * TEXT_TabbedTextOut - * - * Helper function for TabbedTextOut() and GetTabbedTextExtent(). - * Note: this doesn't work too well for text-alignment modes other - * than TA_LEFT|TA_TOP. But we want bug-for-bug compatibility :-) - */ -LONG TEXT_TabbedTextOutW( HDC hdc, INT x, INT y, LPCWSTR lpstr, - INT count, INT cTabStops, const INT *lpTabPos, - INT nTabOrg, WINBOOL fDisplayText ) -{ - INT defWidth; - DWORD extent = 0; - int i, tabPos = x; - int start = x; - SIZE szSize; - - if (cTabStops == 1) - { - defWidth = lpTabPos ? *lpTabPos : 0; - cTabStops = 0; - } - else - { - TEXTMETRIC tm; - GetTextMetricsW( hdc, &tm ); - defWidth = 8 * tm.tmAveCharWidth; - } - - while (count > 0) - { - for (i = 0; i < count; i++) - if (lpstr[i] == '\t') break; - GetTextExtentPoint32W( hdc, lpstr, i, &szSize ); - extent = szSize.cx; - if (lpTabPos) - { - while ((cTabStops > 0) && - (nTabOrg + *lpTabPos <= x + LOWORD(extent))) - { - lpTabPos++; - cTabStops--; - } - } - else - { - while ((cTabStops > 0) && - (nTabOrg + *lpTabPos <= x + LOWORD(extent))) - { - lpTabPos++; - cTabStops--; - } - } - if (i == count) - tabPos = x + LOWORD(extent); - else if (cTabStops > 0) - tabPos = nTabOrg + (lpTabPos ? *lpTabPos : 0); - else - tabPos = nTabOrg + ((x + LOWORD(extent) - nTabOrg) / defWidth + 1) * defWidth; - if (fDisplayText) - { - RECT r; - SetRect( &r, x, y, tabPos, y+HIWORD(extent) ); - ExtTextOutW( hdc, x, y, - GetBkMode(hdc) == OPAQUE ? ETO_OPAQUE : 0, - &r, lpstr, i, NULL ); - } - x = tabPos; - count -= i+1; - lpstr += i+1; - } - return MAKELONG(tabPos - start, HIWORD(extent)); -} -#if 0 -int _alloca(int x) -{ - return malloc(x); -} -#endif \ No newline at end of file diff --git a/reactos/lib/user32/internal/timer.c b/reactos/lib/user32/internal/timer.c deleted file mode 100644 index 7784073ff72..00000000000 --- a/reactos/lib/user32/internal/timer.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * Timer functions - * - * Copyright 1993 Alexandre Julliard - */ - -#include -#include -#include - - - - -static TIMER TimersArray[NB_TIMERS]; - -static TIMER * pNextTimer = NULL; /* Next timer to expire */ - - /* Duration from 'time' until expiration of the timer */ -#define EXPIRE_TIME(pTimer,time) \ - (((pTimer)->expires <= (time)) ? 0 : (pTimer)->expires - (time)) - - -/*********************************************************************** - * TIMER_InsertTimer - * - * Insert the timer at its place in the chain. - */ -void TIMER_InsertTimer( TIMER * pTimer ) -{ - if (!pNextTimer || (pTimer->expires < pNextTimer->expires)) - { - pTimer->next = pNextTimer; - pNextTimer = pTimer; - } - else - { - TIMER * ptr = pNextTimer; - while (ptr->next && (pTimer->expires >= ptr->next->expires)) - ptr = ptr->next; - pTimer->next = ptr->next; - ptr->next = pTimer; - } -} - - -/*********************************************************************** - * TIMER_RemoveTimer - * - * Remove the timer from the chain. - */ -void TIMER_RemoveTimer( TIMER * pTimer ) -{ - TIMER **ppTimer = &pNextTimer; - - while (*ppTimer && (*ppTimer != pTimer)) ppTimer = &(*ppTimer)->next; - if (*ppTimer) *ppTimer = pTimer->next; - pTimer->next = NULL; - if (!pTimer->expires) QUEUE_DecTimerCount( pTimer->hq ); -} - - -/*********************************************************************** - * TIMER_ClearTimer - * - * Clear and remove a timer. - */ -void TIMER_ClearTimer( TIMER * pTimer ) -{ - TIMER_RemoveTimer( pTimer ); - pTimer->hwnd = 0; - pTimer->msg = 0; - pTimer->id = 0; - pTimer->timeout = 0; - //WINPROC_FreeProc( pTimer->proc, WIN_PROC_TIMER ); -} - - -/*********************************************************************** - * TIMER_SwitchQueue - */ -void TIMER_SwitchQueue( HQUEUE old, HQUEUE newQ ) -{ - TIMER * pT = pNextTimer; - - while (pT) - { - if (pT->hq == old) pT->hq = newQ; - pT = pT->next; - } -} - - -/*********************************************************************** - * TIMER_RemoveWindowTimers - * - * Remove all timers for a given window. - */ -void TIMER_RemoveWindowTimers( HWND hwnd ) -{ - int i; - TIMER *pTimer; - - for (i = NB_TIMERS, pTimer = TimersArray; i > 0; i--, pTimer++) - if ((pTimer->hwnd == hwnd) && pTimer->timeout) - TIMER_ClearTimer( pTimer ); -} - - -/*********************************************************************** - * TIMER_RemoveQueueTimers - * - * Remove all timers for a given queue. - */ -void TIMER_RemoveQueueTimers( HQUEUE hqueue ) -{ - int i; - TIMER *pTimer; - - for (i = NB_TIMERS, pTimer = TimersArray; i > 0; i--, pTimer++) - if ((pTimer->hq == hqueue) && pTimer->timeout) - TIMER_ClearTimer( pTimer ); -} - - -/*********************************************************************** - * TIMER_RestartTimers - * - * Restart an expired timer. - */ -void TIMER_RestartTimer( TIMER * pTimer, DWORD curTime ) -{ - TIMER_RemoveTimer( pTimer ); - pTimer->expires = curTime + pTimer->timeout; - TIMER_InsertTimer( pTimer ); -} - - -/*********************************************************************** - * TIMER_GetNextExpiration - * - * Return next timer expiration time, or -1 if none. - */ -LONG TIMER_GetNextExpiration(void) -{ - return pNextTimer ? EXPIRE_TIME( pNextTimer, GetTickCount() ) : -1; -} - - -/*********************************************************************** - * TIMER_ExpireTimers - * - * Mark expired timers and wake the appropriate queues. - */ -void TIMER_ExpireTimers(void) -{ - TIMER *pTimer = pNextTimer; - DWORD curTime = GetTickCount(); - - while (pTimer && !pTimer->expires) /* Skip already expired timers */ - pTimer = pTimer->next; - while (pTimer && (pTimer->expires <= curTime)) - { - pTimer->expires = 0; - QUEUE_IncTimerCount( pTimer->hq ); - pTimer = pTimer->next; - } -} - - -/*********************************************************************** - * TIMER_GetTimerMsg - * - * Build a message for an expired timer. - */ -WINBOOL TIMER_GetTimerMsg( MSG *msg, HWND hwnd, - HQUEUE hQueue,WINBOOL remove ) -{ - TIMER *pTimer = pNextTimer; - DWORD curTime = GetTickCount(); - - if (hwnd) /* Find first timer for this window */ - while (pTimer && (pTimer->hwnd != hwnd)) pTimer = pTimer->next; - else /* Find first timer for this queue */ - while (pTimer && (pTimer->hq != hQueue)) pTimer = pTimer->next; - - if (!pTimer || (pTimer->expires > curTime)) return FALSE; /* No timer */ - if (remove) TIMER_RestartTimer( pTimer, curTime ); /* Restart it */ - - DPRINT( "Timer expired: %04x, %04x, %04x, %08lx\n", - pTimer->hwnd, pTimer->msg, pTimer->id, (DWORD)pTimer->proc); - - /* Build the message */ - msg->hwnd = (HWND)pTimer->hwnd; - msg->message = pTimer->msg; - msg->wParam = (UINT)pTimer->id; - msg->lParam = (LONG)pTimer->proc; - msg->time = curTime; - return TRUE; -} - - -/*********************************************************************** - * TIMER_SetTimer - */ -UINT TIMER_SetTimer( HWND hwnd, UINT id, UINT timeout, - TIMERPROC proc, WINBOOL sys ) -{ - int i; - TIMER * pTimer; - - int type = 0; - - if (!timeout) return 0; - - /* Check if there's already a timer with the same hwnd and id */ - - for (i = 0, pTimer = TimersArray; i < NB_TIMERS; i++, pTimer++) - if ((pTimer->hwnd == hwnd) && (pTimer->id == id) && - (pTimer->timeout != 0)) - { - /* Got one: set new values and return */ - TIMER_RemoveTimer( pTimer ); - pTimer->timeout = timeout; - // WINPROC_FreeProc( pTimer->proc, WIN_PROC_TIMER ); - pTimer->proc = (HWINDOWPROC)0; - if (proc) { - pTimer->proc = proc; - //WINPROC_SetProc( &pTimer->proc, proc, type,WIN_PROC_TIMER ); - } - pTimer->expires = GetTickCount() + timeout; - TIMER_InsertTimer( pTimer ); - return id; - } - - /* Find a free timer */ - - for (i = 0, pTimer = TimersArray; i < NB_TIMERS; i++, pTimer++) - if (!pTimer->timeout) break; - - if (i >= NB_TIMERS) return 0; - if (!sys && (i >= NB_TIMERS-NB_RESERVED_TIMERS)) return 0; - if (!hwnd) id = i + 1; - - /* Add the timer */ - - pTimer->hwnd = hwnd; - pTimer->hq = (hwnd) ? GetThreadQueue( GetWindowThreadProcessId( hwnd, NULL ) ) - : GetFastQueue( ); - pTimer->msg = sys ? WM_SYSTIMER : WM_TIMER; - pTimer->id = id; - pTimer->timeout = timeout; - pTimer->expires = GetTickCount() + timeout; - pTimer->proc = (HWINDOWPROC)0; - if (proc) { - pTimer->proc = proc; - // WINPROC_SetProc( &pTimer->proc, proc, type, WIN_PROC_TIMER ); - } - DPRINT( "Timer added: %p, %04x, %04x, %04x, %08lx\n", - pTimer, pTimer->hwnd, pTimer->msg, pTimer->id, - (DWORD)pTimer->proc ); - TIMER_InsertTimer( pTimer ); - if (!id) return TRUE; - else return id; -} - - -/*********************************************************************** - * TIMER_KillTimer - */ -WINBOOL TIMER_KillTimer( HWND hwnd, UINT id,WINBOOL sys ) -{ - int i; - TIMER * pTimer; - - /* Find the timer */ - - for (i = 0, pTimer = TimersArray; i < NB_TIMERS; i++, pTimer++) - if ((pTimer->hwnd == hwnd) && (pTimer->id == id) && - (pTimer->timeout != 0)) break; - if (i >= NB_TIMERS) return FALSE; - if (!sys && (i >= NB_TIMERS-NB_RESERVED_TIMERS)) return FALSE; - if (!sys && (pTimer->msg != WM_TIMER)) return FALSE; - else if (sys && (pTimer->msg != WM_SYSTIMER)) return FALSE; - - /* Delete the timer */ - - TIMER_ClearTimer( pTimer ); - return TRUE; -} - - - - diff --git a/reactos/lib/user32/internal/uitools.c b/reactos/lib/user32/internal/uitools.c deleted file mode 100644 index 427de6f01b6..00000000000 --- a/reactos/lib/user32/internal/uitools.c +++ /dev/null @@ -1,1326 +0,0 @@ -/* - * User Interface Functions - * - * Copyright 1997 Dimitrie O. Paun - * Copyright 1997 Bertho A. Stultiens - */ - -#include -#include -#include - - -static const WORD wPattern_AA55[8] = { 0xaaaa, 0x5555, 0xaaaa, 0x5555, - 0xaaaa, 0x5555, 0xaaaa, 0x5555 }; - -/* These tables are used in: - * UITOOLS_DrawDiagEdge() - * UITOOLS_DrawRectEdge() - */ - - - -#define BDR_OUTER 0x0003 -#define BDR_INNER 0x000c -#define BDR_RAISED 0x0005 -#define BDR_SUNKEN 0x000a - -static const char LTInnerNormal[] = { - -1, -1, -1, -1, - -1, COLOR_BTNHIGHLIGHT, COLOR_BTNHIGHLIGHT, -1, - -1, COLOR_3DDKSHADOW, COLOR_3DDKSHADOW, -1, - -1, -1, -1, -1 -}; - -static const char LTOuterNormal[] = { - -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1, - COLOR_BTNHIGHLIGHT, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1, - COLOR_3DDKSHADOW, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1, - -1, COLOR_3DLIGHT, COLOR_BTNSHADOW, -1 -}; - -static const char RBInnerNormal[] = { - -1, -1, -1, -1, - -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1, - -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1, - -1, -1, -1, -1 -}; - -static const char RBOuterNormal[] = { - -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1, - COLOR_BTNSHADOW, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1, - COLOR_3DLIGHT, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1, - -1, COLOR_3DDKSHADOW, COLOR_BTNHIGHLIGHT, -1 -}; - -static const char LTInnerSoft[] = { - -1, -1, -1, -1, - -1, COLOR_3DLIGHT, COLOR_3DLIGHT, -1, - -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -1, - -1, -1, -1, -1 -}; - -static const char LTOuterSoft[] = { - -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1, - COLOR_3DLIGHT, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1, - COLOR_BTNSHADOW, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1, - -1, COLOR_BTNHIGHLIGHT, COLOR_3DDKSHADOW, -1 -}; - -#define RBInnerSoft RBInnerNormal /* These are the same */ -#define RBOuterSoft RBOuterNormal - -static const char LTRBOuterMono[] = { - -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, - COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, - COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, - COLOR_WINDOW, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, -}; - -static const char LTRBInnerMono[] = { - -1, -1, -1, -1, - -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW, - -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW, - -1, COLOR_WINDOW, COLOR_WINDOW, COLOR_WINDOW, -}; - -static const char LTRBOuterFlat[] = { - -1, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW, - COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW, - COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW, - COLOR_WINDOWFRAME, COLOR_BTNSHADOW, COLOR_BTNSHADOW, COLOR_BTNSHADOW, -}; - -static const char LTRBInnerFlat[] = { - -1, -1, -1, -1, - -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, - -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, - -1, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, COLOR_WINDOWFRAME, -}; - -/*********************************************************************** - * UITOOLS_DrawDiagEdge - * - * Same as DrawEdge invoked with BF_DIAGONAL - * - * 03-Dec-1997: Changed by Bertho Stultiens - * - * See also comments with UITOOLS_DrawRectEdge() - */ -WINBOOL UITOOLS95_DrawDiagEdge(HDC hdc, LPRECT rc, - UINT uType, UINT uFlags) -{ - POINT Points[4]; - char InnerI, OuterI; - HPEN InnerPen, OuterPen; - POINT SavePoint; - HPEN SavePen; - int spx, spy; - int epx, epy; - int Width = rc->right - rc->left; - int Height= rc->bottom - rc->top; - int SmallDiam = Width > Height ? Height : Width; - WINBOOL retval = !( ((uType & BDR_INNER) == BDR_INNER - || (uType & BDR_OUTER) == BDR_OUTER) - && !(uFlags & (BF_FLAT|BF_MONO)) ); - int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0) - + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0); - - /* Init some vars */ - OuterPen = InnerPen = (HPEN)GetStockObject(NULL_PEN); - SavePen = (HPEN)SelectObject(hdc, InnerPen); - spx = spy = epx = epy = 0; /* Satisfy the compiler... */ - - /* Determine the colors of the edges */ - if(uFlags & BF_MONO) - { - InnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)]; - OuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)]; - } - else if(uFlags & BF_FLAT) - { - InnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)]; - OuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)]; - } - else if(uFlags & BF_SOFT) - { - if(uFlags & BF_BOTTOM) - { - InnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)]; - OuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)]; - } - else - { - InnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)]; - OuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)]; - } - } - else - { - if(uFlags & BF_BOTTOM) - { - InnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)]; - OuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)]; - } - else - { - InnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)]; - OuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)]; - } - } - - if(InnerI != -1) InnerPen = GetSysColorPen(InnerI); - if(OuterI != -1) OuterPen = GetSysColorPen(OuterI); - - MoveToEx(hdc, 0, 0, &SavePoint); - - /* Don't ask me why, but this is what is visible... */ - /* This must be possible to do much simpler, but I fail to */ - /* see the logic in the MS implementation (sigh...). */ - /* So, this might look a bit brute force here (and it is), but */ - /* it gets the job done;) */ - - switch(uFlags & BF_RECT) - { - case 0: - case BF_LEFT: - case BF_BOTTOM: - case BF_BOTTOMLEFT: - /* Left bottom endpoint */ - epx = rc->left-1; - spx = epx + SmallDiam; - epy = rc->bottom; - spy = epy - SmallDiam; - break; - - case BF_TOPLEFT: - case BF_BOTTOMRIGHT: - /* Left top endpoint */ - epx = rc->left-1; - spx = epx + SmallDiam; - epy = rc->top-1; - spy = epy + SmallDiam; - break; - - case BF_TOP: - case BF_RIGHT: - case BF_TOPRIGHT: - case BF_RIGHT|BF_LEFT: - case BF_RIGHT|BF_LEFT|BF_TOP: - case BF_BOTTOM|BF_TOP: - case BF_BOTTOM|BF_TOP|BF_LEFT: - case BF_BOTTOMRIGHT|BF_LEFT: - case BF_BOTTOMRIGHT|BF_TOP: - case BF_RECT: - /* Right top endpoint */ - spx = rc->left; - epx = spx + SmallDiam; - spy = rc->bottom-1; - epy = spy - SmallDiam; - break; - } - - MoveToEx(hdc, spx, spy, NULL); - SelectObject(hdc, OuterPen); - LineTo(hdc, epx, epy); - - SelectObject(hdc, InnerPen); - - switch(uFlags & (BF_RECT|BF_DIAGONAL)) - { - case BF_DIAGONAL_ENDBOTTOMLEFT: - case (BF_DIAGONAL|BF_BOTTOM): - case BF_DIAGONAL: - case (BF_DIAGONAL|BF_LEFT): - MoveToEx(hdc, spx-1, spy, NULL); - LineTo(hdc, epx, epy-1); - Points[0].x = spx-add; - Points[0].y = spy; - Points[1].x = rc->left; - Points[1].y = rc->top; - Points[2].x = epx+1; - Points[2].y = epy-1-add; - Points[3] = Points[2]; - break; - - case BF_DIAGONAL_ENDBOTTOMRIGHT: - MoveToEx(hdc, spx-1, spy, NULL); - LineTo(hdc, epx, epy+1); - Points[0].x = spx-add; - Points[0].y = spy; - Points[1].x = rc->left; - Points[1].y = rc->bottom-1; - Points[2].x = epx+1; - Points[2].y = epy+1+add; - Points[3] = Points[2]; - break; - - case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP): - case (BF_DIAGONAL|BF_BOTTOM|BF_RIGHT|BF_TOP|BF_LEFT): - case BF_DIAGONAL_ENDTOPRIGHT: - case (BF_DIAGONAL|BF_RIGHT|BF_TOP|BF_LEFT): - MoveToEx(hdc, spx+1, spy, NULL); - LineTo(hdc, epx, epy+1); - Points[0].x = epx-1; - Points[0].y = epy+1+add; - Points[1].x = rc->right-1; - Points[1].y = rc->top+add; - Points[2].x = rc->right-1; - Points[2].y = rc->bottom-1; - Points[3].x = spx+add; - Points[3].y = spy; - break; - - case BF_DIAGONAL_ENDTOPLEFT: - MoveToEx(hdc, spx, spy-1, NULL); - LineTo(hdc, epx+1, epy); - Points[0].x = epx+1+add; - Points[0].y = epy+1; - Points[1].x = rc->right-1; - Points[1].y = rc->top; - Points[2].x = rc->right-1; - Points[2].y = rc->bottom-1-add; - Points[3].x = spx; - Points[3].y = spy-add; - break; - - case (BF_DIAGONAL|BF_TOP): - case (BF_DIAGONAL|BF_BOTTOM|BF_TOP): - case (BF_DIAGONAL|BF_BOTTOM|BF_TOP|BF_LEFT): - MoveToEx(hdc, spx+1, spy-1, NULL); - LineTo(hdc, epx, epy); - Points[0].x = epx-1; - Points[0].y = epy+1; - Points[1].x = rc->right-1; - Points[1].y = rc->top; - Points[2].x = rc->right-1; - Points[2].y = rc->bottom-1-add; - Points[3].x = spx+add; - Points[3].y = spy-add; - break; - - case (BF_DIAGONAL|BF_RIGHT): - case (BF_DIAGONAL|BF_RIGHT|BF_LEFT): - case (BF_DIAGONAL|BF_RIGHT|BF_LEFT|BF_BOTTOM): - MoveToEx(hdc, spx, spy, NULL); - LineTo(hdc, epx-1, epy+1); - Points[0].x = spx; - Points[0].y = spy; - Points[1].x = rc->left; - Points[1].y = rc->top+add; - Points[2].x = epx-1-add; - Points[2].y = epy+1+add; - Points[3] = Points[2]; - break; - } - - /* Fill the interior if asked */ - if((uFlags & BF_MIDDLE) && retval) - { - HBRUSH hbsave; - HBRUSH hb = GetSysColorBrush(uFlags & BF_MONO ? COLOR_WINDOW - :COLOR_BTNFACE); - HPEN hpsave; - HPEN hp = GetSysColorPen(uFlags & BF_MONO ? COLOR_WINDOW - : COLOR_BTNFACE); - hbsave = (HBRUSH)SelectObject(hdc, hb); - hpsave = (HPEN)SelectObject(hdc, hp); - Polygon(hdc, Points, 4); - SelectObject(hdc, hbsave); - SelectObject(hdc, hpsave); - } - - /* Adjust rectangle if asked */ - if(uFlags & BF_ADJUST) - { - if(uFlags & BF_LEFT) rc->left += add; - if(uFlags & BF_RIGHT) rc->right -= add; - if(uFlags & BF_TOP) rc->top += add; - if(uFlags & BF_BOTTOM) rc->bottom -= add; - } - - /* Cleanup */ - SelectObject(hdc, SavePen); - MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL); - - return retval; -} - -/*********************************************************************** - * UITOOLS_DrawRectEdge - * - * Same as DrawEdge invoked without BF_DIAGONAL - * - * 23-Nov-1997: Changed by Bertho Stultiens - * - * Well, I started testing this and found out that there are a few things - * that weren't quite as win95. The following rewrite should reproduce - * win95 results completely. - * The colorselection is table-driven to avoid awfull if-statements. - * The table below show the color settings. - * - * Pen selection table for uFlags = 0 - * - * uType | LTI | LTO | RBI | RBO - * ------+-------+-------+-------+------- - * 0000 | x | x | x | x - * 0001 | x | 22 | x | 21 - * 0010 | x | 16 | x | 20 - * 0011 | x | x | x | x - * ------+-------+-------+-------+------- - * 0100 | x | 20 | x | 16 - * 0101 | 20 | 22 | 16 | 21 - * 0110 | 20 | 16 | 16 | 20 - * 0111 | x | x | x | x - * ------+-------+-------+-------+------- - * 1000 | x | 21 | x | 22 - * 1001 | 21 | 22 | 22 | 21 - * 1010 | 21 | 16 | 22 | 20 - * 1011 | x | x | x | x - * ------+-------+-------+-------+------- - * 1100 | x | x | x | x - * 1101 | x | x (22)| x | x (21) - * 1110 | x | x (16)| x | x (20) - * 1111 | x | x | x | x - * - * Pen selection table for uFlags = BF_SOFT - * - * uType | LTI | LTO | RBI | RBO - * ------+-------+-------+-------+------- - * 0000 | x | x | x | x - * 0001 | x | 20 | x | 21 - * 0010 | x | 21 | x | 20 - * 0011 | x | x | x | x - * ------+-------+-------+-------+------- - * 0100 | x | 22 | x | 16 - * 0101 | 22 | 20 | 16 | 21 - * 0110 | 22 | 21 | 16 | 20 - * 0111 | x | x | x | x - * ------+-------+-------+-------+------- - * 1000 | x | 16 | x | 22 - * 1001 | 16 | 20 | 22 | 21 - * 1010 | 16 | 21 | 22 | 20 - * 1011 | x | x | x | x - * ------+-------+-------+-------+------- - * 1100 | x | x | x | x - * 1101 | x | x (20)| x | x (21) - * 1110 | x | x (21)| x | x (20) - * 1111 | x | x | x | x - * - * x = don't care; (n) = is what win95 actually uses - * LTI = left Top Inner line - * LTO = left Top Outer line - * RBI = Right Bottom Inner line - * RBO = Right Bottom Outer line - * 15 = COLOR_BTNFACE - * 16 = COLOR_BTNSHADOW - * 20 = COLOR_BTNHIGHLIGHT - * 21 = COLOR_3DDKSHADOW - * 22 = COLOR_3DLIGHT - */ - - -WINBOOL UITOOLS95_DrawRectEdge(HDC hdc, LPRECT rc, - UINT uType, UINT uFlags) -{ - char LTInnerI, LTOuterI; - char RBInnerI, RBOuterI; - HPEN LTInnerPen, LTOuterPen; - HPEN RBInnerPen, RBOuterPen; - RECT InnerRect = *rc; - POINT SavePoint; - HPEN SavePen; - int LBpenplus = 0; - int LTpenplus = 0; - int RTpenplus = 0; - int RBpenplus = 0; - WINBOOL retval = !( ((uType & BDR_INNER) == BDR_INNER - || (uType & BDR_OUTER) == BDR_OUTER) - && !(uFlags & (BF_FLAT|BF_MONO)) ); - - /* Init some vars */ - LTInnerPen = LTOuterPen = RBInnerPen = RBOuterPen = (HPEN)GetStockObject(NULL_PEN); - SavePen = (HPEN)SelectObject(hdc, LTInnerPen); - - /* Determine the colors of the edges */ - if(uFlags & BF_MONO) - { - LTInnerI = RBInnerI = LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)]; - LTOuterI = RBOuterI = LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)]; - } - else if(uFlags & BF_FLAT) - { - LTInnerI = RBInnerI = LTRBInnerFlat[uType & (BDR_INNER|BDR_OUTER)]; - LTOuterI = RBOuterI = LTRBOuterFlat[uType & (BDR_INNER|BDR_OUTER)]; - } - else if(uFlags & BF_SOFT) - { - LTInnerI = LTInnerSoft[uType & (BDR_INNER|BDR_OUTER)]; - LTOuterI = LTOuterSoft[uType & (BDR_INNER|BDR_OUTER)]; - RBInnerI = RBInnerSoft[uType & (BDR_INNER|BDR_OUTER)]; - RBOuterI = RBOuterSoft[uType & (BDR_INNER|BDR_OUTER)]; - } - else - { - LTInnerI = LTInnerNormal[uType & (BDR_INNER|BDR_OUTER)]; - LTOuterI = LTOuterNormal[uType & (BDR_INNER|BDR_OUTER)]; - RBInnerI = RBInnerNormal[uType & (BDR_INNER|BDR_OUTER)]; - RBOuterI = RBOuterNormal[uType & (BDR_INNER|BDR_OUTER)]; - } - - if((uFlags & BF_BOTTOMLEFT) == BF_BOTTOMLEFT) LBpenplus = 1; - if((uFlags & BF_TOPRIGHT) == BF_TOPRIGHT) RTpenplus = 1; - if((uFlags & BF_BOTTOMRIGHT) == BF_BOTTOMRIGHT) RBpenplus = 1; - if((uFlags & BF_TOPLEFT) == BF_TOPLEFT) LTpenplus = 1; - - if(LTInnerI != -1) LTInnerPen = GetSysColorPen(LTInnerI); - if(LTOuterI != -1) LTOuterPen = GetSysColorPen(LTOuterI); - if(RBInnerI != -1) RBInnerPen = GetSysColorPen(RBInnerI); - if(RBOuterI != -1) RBOuterPen = GetSysColorPen(RBOuterI); - - if((uFlags & BF_MIDDLE) && retval) - { - FillRect(hdc, &InnerRect, GetSysColorBrush(uFlags & BF_MONO ? - COLOR_WINDOW : COLOR_BTNFACE)); - } - - MoveToEx(hdc, 0, 0, &SavePoint); - - /* Draw the outer edge */ - SelectObject(hdc, LTOuterPen); - if(uFlags & BF_TOP) - { - MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL); - LineTo(hdc, InnerRect.right, InnerRect.top); - } - if(uFlags & BF_LEFT) - { - MoveToEx(hdc, InnerRect.left, InnerRect.top, NULL); - LineTo(hdc, InnerRect.left, InnerRect.bottom); - } - SelectObject(hdc, RBOuterPen); - if(uFlags & BF_BOTTOM) - { - MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL); - LineTo(hdc, InnerRect.left-1, InnerRect.bottom-1); - } - if(uFlags & BF_RIGHT) - { - MoveToEx(hdc, InnerRect.right-1, InnerRect.bottom-1, NULL); - LineTo(hdc, InnerRect.right-1, InnerRect.top-1); - } - - /* Draw the inner edge */ - SelectObject(hdc, LTInnerPen); - if(uFlags & BF_TOP) - { - MoveToEx(hdc, InnerRect.left+LTpenplus, InnerRect.top+1, NULL); - LineTo(hdc, InnerRect.right-RTpenplus, InnerRect.top+1); - } - if(uFlags & BF_LEFT) - { - MoveToEx(hdc, InnerRect.left+1, InnerRect.top+LTpenplus, NULL); - LineTo(hdc, InnerRect.left+1, InnerRect.bottom-LBpenplus); - } - SelectObject(hdc, RBInnerPen); - if(uFlags & BF_BOTTOM) - { - MoveToEx(hdc, InnerRect.right-1-RBpenplus, InnerRect.bottom-2, NULL); - LineTo(hdc, InnerRect.left-1+LBpenplus, InnerRect.bottom-2); - } - if(uFlags & BF_RIGHT) - { - MoveToEx(hdc, InnerRect.right-2, InnerRect.bottom-1-RBpenplus, NULL); - LineTo(hdc, InnerRect.right-2, InnerRect.top-1+RTpenplus); - } - - /* Adjust rectangle if asked */ - if(uFlags & BF_ADJUST) - { - int add = (LTRBInnerMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0) - + (LTRBOuterMono[uType & (BDR_INNER|BDR_OUTER)] != -1 ? 1 : 0); - if(uFlags & BF_LEFT) rc->left += add; - if(uFlags & BF_RIGHT) rc->right -= add; - if(uFlags & BF_TOP) rc->top += add; - if(uFlags & BF_BOTTOM) rc->bottom -= add; - } - - /* Cleanup */ - SelectObject(hdc, SavePen); - MoveToEx(hdc, SavePoint.x, SavePoint.y, NULL); - return retval; -} - -/************************************************************************ - * UITOOLS_MakeSquareRect - * - * Utility to create a square rectangle and returning the width - */ -int UITOOLS_MakeSquareRect(LPRECT src, LPRECT dst) -{ - int Width = src->right - src->left; - int Height = src->bottom - src->top; - int SmallDiam = Width > Height ? Height : Width; - - *dst = *src; - - /* Make it a square box */ - if(Width < Height) /* SmallDiam == Width */ - { - dst->top += (Height-Width)/2; - dst->bottom = dst->top + SmallDiam; - } - else if(Width > Height) /* SmallDiam == Height */ - { - dst->left += (Width-Height)/2; - dst->right = dst->left + SmallDiam; - } - - return SmallDiam; -} - - -/************************************************************************ - * UITOOLS_DFC_ButtonPush - * - * Draw a push button coming from DrawFrameControl() - * - * Does a pretty good job in emulating MS behavior. Some quirks are - * however there because MS uses a TrueType font (Marlett) to draw - * the buttons. - */ -WINBOOL UITOOLS95_DFC_ButtonPush(HDC dc, LPRECT r, UINT uFlags) -{ - UINT edge; - RECT myr = *r; - - if(uFlags & (DFCS_PUSHED | DFCS_CHECKED | DFCS_FLAT)) - edge = EDGE_SUNKEN; - else - edge = EDGE_RAISED; - - if(uFlags & DFCS_CHECKED) - { - if(uFlags & DFCS_MONO) - UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST); - else - UITOOLS95_DrawRectEdge(dc, &myr, edge, (uFlags&DFCS_FLAT)|BF_RECT|BF_SOFT|BF_ADJUST); - - if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255)) - { - HBITMAP hbm = CreateBitmap(8, 8, 1, 1, wPattern_AA55); - HBRUSH hbsave; - HBRUSH hb = CreatePatternBrush(hbm); - - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE)); - hbsave = (HBRUSH)SelectObject(dc, hb); - PatBlt(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089); - SelectObject(dc, hbsave); - DeleteObject(hb); - DeleteObject(hbm); - } - else - { - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - } - } - else - { - if(uFlags & DFCS_MONO) - { - UITOOLS95_DrawRectEdge(dc, &myr, edge, BF_MONO|BF_RECT|BF_ADJUST); - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE)); - } - else - { - UITOOLS95_DrawRectEdge(dc, r, edge, (uFlags&DFCS_FLAT) | BF_MIDDLE |BF_SOFT| BF_RECT); - } - } - - /* Adjust rectangle if asked */ - if(uFlags & DFCS_ADJUSTRECT) - { - r->left += 2; - r->right -= 2; - r->top += 2; - r->bottom -= 2; - } - - return TRUE; -} - - -/************************************************************************ - * UITOOLS_DFC_ButtonChcek - * - * Draw a check/3state button coming from DrawFrameControl() - * - * Does a pretty good job in emulating MS behavior. Some quirks are - * however there because MS uses a TrueType font (Marlett) to draw - * the buttons. - */ -#define DFC_CHECKPOINTSMAX 6 - -WINBOOL UITOOLS95_DFC_ButtonCheck(HDC dc, LPRECT r, UINT uFlags) -{ - RECT myr; - int SmallDiam = UITOOLS_MakeSquareRect(r, &myr); - int BorderShrink = SmallDiam / 16; - - if(BorderShrink < 1) BorderShrink = 1; - - /* FIXME: The FillRect() sequence doesn't work for sizes less than */ - /* 4 pixels in diameter. Not really a problem but it isn't M$'s */ - /* 100% equivalent. */ - if(uFlags & (DFCS_FLAT|DFCS_MONO)) - { - FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOWFRAME)); - myr.left += 2 * BorderShrink; - myr.right -= 2 * BorderShrink; - myr.top += 2 * BorderShrink; - myr.bottom -= 2 * BorderShrink; - } - else - { - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - myr.right -= BorderShrink; - myr.bottom -= BorderShrink; - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNSHADOW)); - myr.left += BorderShrink; - myr.top += BorderShrink; - FillRect(dc, &myr, GetSysColorBrush(COLOR_3DLIGHT)); - myr.right -= BorderShrink; - myr.bottom -= BorderShrink; - FillRect(dc, &myr, GetSysColorBrush(COLOR_3DDKSHADOW)); - myr.left += BorderShrink; - myr.top += BorderShrink; - } - - if(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) - { - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE)); - } - else if(uFlags & DFCS_CHECKED) - { - if(GetSysColor(COLOR_BTNHIGHLIGHT) == RGB(255, 255, 255)) - { - HBITMAP hbm = CreateBitmap(8, 8, 1, 1, wPattern_AA55); - HBRUSH hbsave; - HBRUSH hb = CreatePatternBrush(hbm); - - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNFACE)); - hbsave = (HBRUSH)SelectObject(dc, hb); - PatBlt(dc, myr.left, myr.top, myr.right-myr.left, myr.bottom-myr.top, 0x00FA0089); - SelectObject(dc, hbsave); - DeleteObject(hb); - DeleteObject(hbm); - } - else - { - FillRect(dc, &myr, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - } - } - else - { - FillRect(dc, &myr, GetSysColorBrush(COLOR_WINDOW)); - } - - if(uFlags & DFCS_CHECKED) - { - POINT CheckPoints[DFC_CHECKPOINTSMAX]; - int i; - HBRUSH hbsave; - HPEN hpsave; - - /* FIXME: This comes very close to M$'s checkmark, but not */ - /* exactly... When small or large there is a few pixels */ - /* shift. Not bad, but could be better :) */ - UITOOLS_MakeSquareRect(r, &myr); - CheckPoints[0].x = myr.left + 253*SmallDiam/1000; - CheckPoints[0].y = myr.top + 345*SmallDiam/1000; - CheckPoints[1].x = myr.left + 409*SmallDiam/1000; - CheckPoints[1].y = CheckPoints[0].y + (CheckPoints[1].x-CheckPoints[0].x); - CheckPoints[2].x = myr.left + 690*SmallDiam/1000; - CheckPoints[2].y = CheckPoints[1].y - (CheckPoints[2].x-CheckPoints[1].x); - CheckPoints[3].x = CheckPoints[2].x; - CheckPoints[3].y = CheckPoints[2].y + 3*SmallDiam/16; - CheckPoints[4].x = CheckPoints[1].x; - CheckPoints[4].y = CheckPoints[1].y + 3*SmallDiam/16; - CheckPoints[5].x = CheckPoints[0].x; - CheckPoints[5].y = CheckPoints[0].y + 3*SmallDiam/16; - - i = (uFlags & DFCS_INACTIVE) || (uFlags & 0xff) == DFCS_BUTTON3STATE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT; - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - Polygon(dc, CheckPoints, DFC_CHECKPOINTSMAX); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - } - return TRUE; -} - - -/************************************************************************ - * UITOOLS_DFC_ButtonRadio - * - * Draw a radio/radioimage/radiomask button coming from DrawFrameControl() - * - * Does a pretty good job in emulating MS behavior. Some quirks are - * however there because MS uses a TrueType font (Marlett) to draw - * the buttons. - */ -static WINBOOL UITOOLS95_DFC_ButtonRadio(HDC dc, LPRECT r, UINT uFlags) -{ - RECT myr; - int i; - int SmallDiam = UITOOLS_MakeSquareRect(r, &myr); - int BorderShrink = SmallDiam / 16; - HPEN hpsave; - HBRUSH hbsave; - int xe, ye; - int xc, yc; - - if(BorderShrink < 1) BorderShrink = 1; - - if((uFlags & 0xff) == DFCS_BUTTONRADIOIMAGE) - { - FillRect(dc, r, (HBRUSH)GetStockObject(BLACK_BRUSH)); - } - - xe = myr.left; - ye = myr.top + SmallDiam - SmallDiam/2; - - xc = myr.left + SmallDiam - SmallDiam/2; - yc = myr.top + SmallDiam - SmallDiam/2; - - /* Define bounding box */ - i = 14*SmallDiam/16; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; - - if((uFlags & 0xff) == DFCS_BUTTONRADIOMASK) - { - hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye); - SelectObject(dc, hbsave); - } - else - { - if(uFlags & (DFCS_FLAT|DFCS_MONO)) - { - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_WINDOWFRAME)); - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye); - SelectObject(dc, hbsave); - SelectObject(dc, hpsave); - } - else - { - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT)); - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top); - - SelectObject(dc, GetSysColorPen(COLOR_BTNSHADOW)); - SelectObject(dc, GetSysColorBrush(COLOR_BTNSHADOW)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom); - - myr.left += BorderShrink; - myr.right -= BorderShrink; - myr.top += BorderShrink; - myr.bottom -= BorderShrink; - - SelectObject(dc, GetSysColorPen(COLOR_3DLIGHT)); - SelectObject(dc, GetSysColorBrush(COLOR_3DLIGHT)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.left-1, myr.bottom, myr.right-1, myr.top); - - SelectObject(dc, GetSysColorPen(COLOR_3DDKSHADOW)); - SelectObject(dc, GetSysColorBrush(COLOR_3DDKSHADOW)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, myr.right+1, myr.top, myr.left+1, myr.bottom); - SelectObject(dc, hbsave); - SelectObject(dc, hpsave); - } - - i = 10*SmallDiam/16; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; - i= !(uFlags & (DFCS_INACTIVE|DFCS_PUSHED)) ? COLOR_WINDOW : COLOR_BTNFACE; - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye); - SelectObject(dc, hbsave); - SelectObject(dc, hpsave); - } - - if(uFlags & DFCS_CHECKED) - { - i = 6*SmallDiam/16; - i = i < 1 ? 1 : i; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; - - i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_WINDOWTEXT; - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - } - - /* FIXME: M$ has a polygon in the center at relative points: */ - /* 0.476, 0.476 (times SmallDiam, SmallDiam) */ - /* 0.476, 0.525 */ - /* 0.500, 0.500 */ - /* 0.500, 0.499 */ - /* when the button is unchecked. The reason for it is unknown. The */ - /* color is COLOR_BTNHIGHLIGHT, although the polygon gets painted at */ - /* least 3 times (it looks like a clip-region when you see it happen). */ - /* I do not really see a reason why this should be implemented. If you */ - /* have a good reason, let me know. Maybe this is a quirk in the Marlett */ - /* font. */ - - return TRUE; -} - -/*********************************************************************** - * UITOOLS_DrawFrameButton - */ -static WINBOOL UITOOLS95_DrawFrameButton(HDC hdc, LPRECT rc, UINT uState) -{ - switch(uState & 0xff) - { - case DFCS_BUTTONPUSH: - return UITOOLS95_DFC_ButtonPush(hdc, rc, uState); - - case DFCS_BUTTONCHECK: - case DFCS_BUTTON3STATE: - return UITOOLS95_DFC_ButtonCheck(hdc, rc, uState); - - case DFCS_BUTTONRADIOIMAGE: - case DFCS_BUTTONRADIOMASK: - case DFCS_BUTTONRADIO: - return UITOOLS95_DFC_ButtonRadio(hdc, rc, uState); - - default: - DPRINT( "Invalid button state=0x%04x\n", uState); - } - - return FALSE; -} - -/*********************************************************************** - * UITOOLS_DrawFrameCaption - * - * Draw caption buttons (win95), coming from DrawFrameControl() - */ - -static WINBOOL UITOOLS95_DrawFrameCaption(HDC dc, LPRECT r, UINT uFlags) -{ - POINT Line1[10]; - POINT Line2[10]; - int Line1N; - int Line2N; - RECT myr; - int SmallDiam = UITOOLS_MakeSquareRect(r, &myr)-2; - int i; - HBRUSH hbsave; - HPEN hpsave; - HFONT hfsave, hf; - int xc = (myr.left+myr.right)/2; - int yc = (myr.top+myr.bottom)/2; - int edge, move; - char str[2] = "?"; - UINT alignsave; - int bksave; - COLORREF clrsave; - SIZE size; - - UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00); - - switch(uFlags & 0xff) - { - case DFCS_CAPTIONCLOSE: - edge = 8*SmallDiam/1000; - move = 95*SmallDiam/1000; - Line1[0].x = Line2[0].x = Line1[1].x = Line2[1].x = xc - edge; - Line1[2].y = Line2[5].y = Line1[1].y = Line2[4].y = yc - edge; - Line1[3].x = Line2[3].x = Line1[4].x = Line2[4].x = xc + edge; - Line1[5].y = Line2[2].y = Line1[4].y = Line2[1].y = yc + edge; - Line1[2].x = Line2[2].x = Line1[1].x + move; - Line1[0].y = Line2[3].y = Line1[1].y + move; - Line1[5].x = Line2[5].x = Line1[4].x - move; - Line1[3].y = Line2[0].y = Line1[4].y - move; - Line1N = 6; - Line2N = 6; - break; - - case DFCS_CAPTIONHELP: - /* This one breaks the flow */ - /* FIXME: We need the Marlett font in order to get this right. */ - - hf = CreateFontA(-SmallDiam, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "System"); - alignsave = SetTextAlign(dc, TA_TOP|TA_LEFT); - bksave = SetBkMode(dc, TRANSPARENT); - clrsave = GetTextColor(dc); - hfsave = (HFONT)SelectObject(dc, hf); - GetTextExtentPointA(dc, str, 1, &size); - - if(uFlags & DFCS_INACTIVE) - { - SetTextColor(dc, GetSysColor(COLOR_BTNHIGHLIGHT)); - TextOutA(dc, xc-size.cx/2+1, yc-size.cy/2+1, str, 1); - } - SetTextColor(dc, GetSysColor(uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT)); - TextOutA(dc, xc-size.cx/2, yc-size.cy/2, str, 1); - - SelectObject(dc, hfsave); - SetTextColor(dc, clrsave); - SetBkMode(dc, bksave); - SetTextAlign(dc, alignsave); - DeleteObject(hf); - return TRUE; - - case DFCS_CAPTIONMIN: - Line1[0].x = Line1[3].x = myr.left + 96*SmallDiam/750+2; - Line1[1].x = Line1[2].x = Line1[0].x + 372*SmallDiam/750; - Line1[0].y = Line1[1].y = myr.top + 563*SmallDiam/750+1; - Line1[2].y = Line1[3].y = Line1[0].y + 92*SmallDiam/750; - Line1N = 4; - Line2N = 0; - break; - - case DFCS_CAPTIONMAX: - edge = 47*SmallDiam/750; - Line1[0].x = Line1[5].x = myr.left + 57*SmallDiam/750+3; - Line1[0].y = Line1[1].y = myr.top + 143*SmallDiam/750+1; - Line1[1].x = Line1[2].x = Line1[0].x + 562*SmallDiam/750; - Line1[5].y = Line1[4].y = Line1[0].y + 93*SmallDiam/750; - Line1[2].y = Line1[3].y = Line1[0].y + 513*SmallDiam/750; - Line1[3].x = Line1[4].x = Line1[1].x - edge; - - Line2[0].x = Line2[5].x = Line1[0].x; - Line2[3].x = Line2[4].x = Line1[1].x; - Line2[1].x = Line2[2].x = Line1[0].x + edge; - Line2[0].y = Line2[1].y = Line1[0].y; - Line2[4].y = Line2[5].y = Line1[2].y; - Line2[2].y = Line2[3].y = Line1[2].y - edge; - Line1N = 6; - Line2N = 6; - break; - - case DFCS_CAPTIONRESTORE: - /* FIXME: this one looks bad at small sizes < 15x15 :( */ - edge = 47*SmallDiam/750; - move = 420*SmallDiam/750; - Line1[0].x = Line1[9].x = myr.left + 198*SmallDiam/750+2; - Line1[0].y = Line1[1].y = myr.top + 169*SmallDiam/750+1; - Line1[6].y = Line1[7].y = Line1[0].y + 93*SmallDiam/750; - Line1[7].x = Line1[8].x = Line1[0].x + edge; - Line1[1].x = Line1[2].x = Line1[0].x + move; - Line1[5].x = Line1[6].x = Line1[1].x - edge; - Line1[9].y = Line1[8].y = Line1[0].y + 187*SmallDiam/750; - Line1[2].y = Line1[3].y = Line1[0].y + 7*SmallDiam/750; - Line1[4].y = Line1[5].y = Line1[2].y - edge; - Line1[3].x = Line1[4].x = Line1[2].x - 140*SmallDiam/750; - - Line2[1].x = Line2[2].x = Line1[3].x; - Line2[7].x = Line2[8].x = Line2[1].x - edge; - Line2[0].x = Line2[9].x = Line2[3].x = Line2[4].x = Line2[1].x - move; - Line2[5].x = Line2[6].x = Line2[0].x + edge; - Line2[0].y = Line2[1].y = Line1[9].y; - Line2[4].y = Line2[5].y = Line2[8].y = Line2[9].y = Line2[0].y + 93*SmallDiam/750; - Line2[2].y = Line2[3].y = Line2[0].y + 7*SmallDiam/750; - Line2[6].y = Line2[7].y = Line2[2].y - edge; - Line1N = 10; - Line2N = 10; - break; - - default: - DPRINT( "Invalid caption; flags=0x%04x\n", uFlags); - return FALSE; - } - - /* Here the drawing takes place */ - if(uFlags & DFCS_INACTIVE) - { - /* If we have an inactive button, then you see a shadow */ - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT)); - Polygon(dc, Line1, Line1N); - if(Line2N > 0) - Polygon(dc, Line2, Line2N); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - } - - /* Correct for the shadow shift */ - for(i = 0; i < Line1N; i++) - { - Line1[i].x--; - Line1[i].y--; - } - for(i = 0; i < Line2N; i++) - { - Line2[i].x--; - Line2[i].y--; - } - - /* Make the final picture */ - i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT; - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - - Polygon(dc, Line1, Line1N); - if(Line2N > 0) - Polygon(dc, Line2, Line2N); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - - return TRUE; -} - - -/************************************************************************ - * UITOOLS_DrawFrameScroll - * - * Draw a scroll-bar control coming from DrawFrameControl() - */ -static WINBOOL UITOOLS95_DrawFrameScroll(HDC dc, LPRECT r, UINT uFlags) -{ - POINT Line[4]; - RECT myr; - int SmallDiam = UITOOLS_MakeSquareRect(r, &myr) - 2; - int i; - HBRUSH hbsave, hb, hb2; - HPEN hpsave, hp, hp2; - int tri = 310*SmallDiam/1000; - int d46, d93; - - switch(uFlags & 0xff) - { - case DFCS_SCROLLCOMBOBOX: - case DFCS_SCROLLDOWN: - Line[2].x = myr.left + 470*SmallDiam/1000 + 2; - Line[2].y = myr.top + 687*SmallDiam/1000 + 1; - Line[0].x = Line[2].x - tri; - Line[1].x = Line[2].x + tri; - Line[0].y = Line[1].y = Line[2].y - tri; - break; - - case DFCS_SCROLLUP: - Line[2].x = myr.left + 470*SmallDiam/1000 + 2; - Line[2].y = myr.top + 313*SmallDiam/1000 + 1; - Line[0].x = Line[2].x - tri; - Line[1].x = Line[2].x + tri; - Line[0].y = Line[1].y = Line[2].y + tri; - break; - - case DFCS_SCROLLLEFT: - Line[2].x = myr.left + 313*SmallDiam/1000 + 1; - Line[2].y = myr.top + 470*SmallDiam/1000 + 2; - Line[0].y = Line[2].y - tri; - Line[1].y = Line[2].y + tri; - Line[0].x = Line[1].x = Line[2].x + tri; - break; - - case DFCS_SCROLLRIGHT: - Line[2].x = myr.left + 687*SmallDiam/1000 + 1; - Line[2].y = myr.top + 470*SmallDiam/1000 + 2; - Line[0].y = Line[2].y - tri; - Line[1].y = Line[2].y + tri; - Line[0].x = Line[1].x = Line[2].x - tri; - break; - - case DFCS_SCROLLSIZEGRIP: - /* This one breaks the flow... */ - UITOOLS95_DrawRectEdge(dc, r, EDGE_BUMP, BF_MIDDLE | ((uFlags&(DFCS_MONO|DFCS_FLAT)) ? BF_MONO : 0)); - hpsave = (HPEN)SelectObject(dc, GetStockObject(NULL_PEN)); - hbsave = (HBRUSH)SelectObject(dc, GetStockObject(NULL_BRUSH)); - if(uFlags & (DFCS_MONO|DFCS_FLAT)) - { - hp = hp2 = GetSysColorPen(COLOR_WINDOWFRAME); - hb = hb2 = GetSysColorBrush(COLOR_WINDOWFRAME); - } - else - { - hp = GetSysColorPen(COLOR_BTNHIGHLIGHT); - hp2 = GetSysColorPen(COLOR_BTNSHADOW); - hb = GetSysColorBrush(COLOR_BTNHIGHLIGHT); - hb2 = GetSysColorBrush(COLOR_BTNSHADOW); - } - Line[0].x = Line[1].x = r->right-1; - Line[2].y = Line[3].y = r->bottom-1; - d46 = 46*SmallDiam/750; - d93 = 93*SmallDiam/750; - - i = 586*SmallDiam/750; - Line[0].y = r->bottom - i - 1; - Line[3].x = r->right - i - 1; - Line[1].y = Line[0].y + d46; - Line[2].x = Line[3].x + d46; - SelectObject(dc, hb); - SelectObject(dc, hp); - Polygon(dc, Line, 4); - - Line[1].y++; Line[2].x++; - Line[0].y = Line[1].y + d93; - Line[3].x = Line[2].x + d93; - SelectObject(dc, hb2); - SelectObject(dc, hp2); - Polygon(dc, Line, 4); - - i = 398*SmallDiam/750; - Line[0].y = r->bottom - i - 1; - Line[3].x = r->right - i - 1; - Line[1].y = Line[0].y + d46; - Line[2].x = Line[3].x + d46; - SelectObject(dc, hb); - SelectObject(dc, hp); - Polygon(dc, Line, 4); - - Line[1].y++; Line[2].x++; - Line[0].y = Line[1].y + d93; - Line[3].x = Line[2].x + d93; - SelectObject(dc, hb2); - SelectObject(dc, hp2); - Polygon(dc, Line, 4); - - i = 210*SmallDiam/750; - Line[0].y = r->bottom - i - 1; - Line[3].x = r->right - i - 1; - Line[1].y = Line[0].y + d46; - Line[2].x = Line[3].x + d46; - SelectObject(dc, hb); - SelectObject(dc, hp); - Polygon(dc, Line, 4); - - Line[1].y++; Line[2].x++; - Line[0].y = Line[1].y + d93; - Line[3].x = Line[2].x + d93; - SelectObject(dc, hb2); - SelectObject(dc, hp2); - Polygon(dc, Line, 4); - - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - return TRUE; - - default: - DPRINT( "Invalid scroll; flags=0x%04x\n", uFlags); - return FALSE; - } - - /* Here do the real scroll-bar controls end up */ - UITOOLS95_DFC_ButtonPush(dc, r, uFlags & 0xff00); - - if(uFlags & DFCS_INACTIVE) - { - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(COLOR_BTNHIGHLIGHT)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(COLOR_BTNHIGHLIGHT)); - Polygon(dc, Line, 3); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - } - - for(i = 0; i < 3; i++) - { - Line[i].x--; - Line[i].y--; - } - - i = uFlags & DFCS_INACTIVE ? COLOR_BTNSHADOW : COLOR_BTNTEXT; - hbsave = (HBRUSH)SelectObject(dc, GetSysColorBrush(i)); - hpsave = (HPEN)SelectObject(dc, GetSysColorPen(i)); - Polygon(dc, Line, 3); - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - - return TRUE; -} - -/************************************************************************ - * UITOOLS_DrawFrameMenu - * - * Draw a menu control coming from DrawFrameControl() - */ -static WINBOOL UITOOLS95_DrawFrameMenu(HDC dc, LPRECT r, UINT uFlags) -{ - POINT Points[6]; - RECT myr; - int SmallDiam = UITOOLS_MakeSquareRect(r, &myr); - int i; - HBRUSH hbsave; - HPEN hpsave; - int xe, ye; - int xc, yc; - WINBOOL retval = TRUE; - - /* Using black and white seems to be utterly wrong, but win95 doesn't */ - /* use anything else. I think I tried all sys-colors to change things */ - /* without luck. It seems as if this behavior is inherited from the */ - /* win31 DFC() implementation... (you remember, B/W menus). */ - - FillRect(dc, r, (HBRUSH)GetStockObject(WHITE_BRUSH)); - - hbsave = (HBRUSH)SelectObject(dc, GetStockObject(BLACK_BRUSH)); - hpsave = (HPEN)SelectObject(dc, GetStockObject(BLACK_PEN)); - - switch(uFlags & 0xff) - { - case DFCS_MENUARROW: - i = 187*SmallDiam/750; - Points[2].x = myr.left + 468*SmallDiam/750; - Points[2].y = myr.top + 352*SmallDiam/750+1; - Points[0].y = Points[2].y - i; - Points[1].y = Points[2].y + i; - Points[0].x = Points[1].x = Points[2].x - i; - Polygon(dc, Points, 3); - break; - - case DFCS_MENUBULLET: - xe = myr.left; - ye = myr.top + SmallDiam - SmallDiam/2; - xc = myr.left + SmallDiam - SmallDiam/2; - yc = myr.top + SmallDiam - SmallDiam/2; - i = 234*SmallDiam/750; - i = i < 1 ? 1 : i; - myr.left = xc - i+i/2; - myr.right = xc + i/2; - myr.top = yc - i+i/2; - myr.bottom = yc + i/2; - Pie(dc, myr.left, myr.top, myr.right, myr.bottom, xe, ye, xe, ye); - break; - - case DFCS_MENUCHECK: - Points[0].x = myr.left + 253*SmallDiam/1000; - Points[0].y = myr.top + 445*SmallDiam/1000; - Points[1].x = myr.left + 409*SmallDiam/1000; - Points[1].y = Points[0].y + (Points[1].x-Points[0].x); - Points[2].x = myr.left + 690*SmallDiam/1000; - Points[2].y = Points[1].y - (Points[2].x-Points[1].x); - Points[3].x = Points[2].x; - Points[3].y = Points[2].y + 3*SmallDiam/16; - Points[4].x = Points[1].x; - Points[4].y = Points[1].y + 3*SmallDiam/16; - Points[5].x = Points[0].x; - Points[5].y = Points[0].y + 3*SmallDiam/16; - Polygon(dc, Points, 6); - break; - - default: - DPRINT( "Invalid menu; flags=0x%04x\n", uFlags); - retval = FALSE; - break; - } - - SelectObject(dc, hpsave); - SelectObject(dc, hbsave); - return retval; -} diff --git a/reactos/lib/user32/internal/win.c b/reactos/lib/user32/internal/win.c deleted file mode 100644 index 44f2e13d503..00000000000 --- a/reactos/lib/user32/internal/win.c +++ /dev/null @@ -1,1103 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -WND *rootWnd; - -////////////////////////////////////////////////////////////////////////////////// - -WND *pWndDesktop = NULL; - - -/*********************************************************************** - * WIN_CreateDesktopWindow - * - * Create the desktop window. - */ -BOOL WIN_CreateDesktopWindow(void) -{ - CLASS *class; - HWND hwndDesktop; - //DESKTOP *pDesktop; - - DPRINT("Creating desktop window\n"); - - - - class = CLASS_FindClassByAtom( STRING2ATOMW(DESKTOP_CLASS_NAME) , 0 ); - if ( class == NULL ) - return FALSE; - - hwndDesktop = HeapAlloc(GetProcessHeap(),0, sizeof(WND)+class->cbWndExtra ); - if (!hwndDesktop) return FALSE; - pWndDesktop = (WND *) ( hwndDesktop ); - - //pDesktop = (DESKTOP *) pWndDesktop->wExtra; - //pDesktop->pDriver = DESKTOP_Driver; - //pWndDesktop->pDriver = WND_Driver; - - //pDesktop->pDriver->pInitialize(pDesktop); - //pWndDesktop->pDriver->pInitialize(pWndDesktop); - - pWndDesktop->next = NULL; - pWndDesktop->child = NULL; - pWndDesktop->parent = NULL; - pWndDesktop->owner = NULL; - pWndDesktop->class = class; - pWndDesktop->dwMagic = WND_MAGIC; - pWndDesktop->hwndSelf = hwndDesktop; - pWndDesktop->hInstance = 0; - pWndDesktop->rectWindow.left = 0; - pWndDesktop->rectWindow.top = 0; - pWndDesktop->rectWindow.right = GetSystemMetrics(SM_CXSCREEN); - pWndDesktop->rectWindow.bottom = GetSystemMetrics(SM_CYSCREEN); - pWndDesktop->rectClient = pWndDesktop->rectWindow; - pWndDesktop->text = NULL; - //pWndDesktop->hmemTaskQ = GetFastQueue16(); - pWndDesktop->hrgnUpdate = 0; - pWndDesktop->hwndLastActive = hwndDesktop; - pWndDesktop->dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | - WS_CLIPSIBLINGS; - pWndDesktop->dwExStyle = 0; - pWndDesktop->dce = DCE_AllocDCE(pWndDesktop,DCE_WINDOW_DC); - pWndDesktop->pVScroll = NULL; - pWndDesktop->pHScroll = NULL; - pWndDesktop->pProp = NULL; - pWndDesktop->wIDmenu = 0; - pWndDesktop->helpContext = 0; - //pWndDesktop->flags = Options.desktopGeometry ? WIN_NATIVE : 0; - pWndDesktop->hSysMenu = 0; - pWndDesktop->userdata = 0; - pWndDesktop->winproc = (WNDPROC)class->winproc; - //pWndDesktop->irefCount = 0; - - /* FIXME: How do we know if it should be Unicode or not */ - //if(!pWndDesktop->pDriver->pCreateDesktopWindow(pWndDesktop, class, FALSE)) - // return FALSE; - - SendMessageA( hwndDesktop, WM_NCCREATE, 0, 0 ); - pWndDesktop->flags |= WIN_NEEDS_ERASEBKGND; - return TRUE; -} - - -HANDLE WIN_CreateWindowEx( CREATESTRUCT *cs, ATOM classAtom) -{ - - WND *wndPtr; - STARTUPINFO StartupInfo; - CLASS *classPtr = NULL; - POINT maxSize, maxPos, minTrack, maxTrack; - HWND hWndLinkAfter = NULL; - /* Create the window structure */ - - #if 0 - if (cs->hwndParent) - { - /* Make sure parent is valid */ - if (!IsWindow( cs->hwndParent )) - { - DPRINT("Bad parent %04x\n", cs->hwndParent ); - return 0; - } - } else if ((cs->style & WS_CHILD) && !(cs->style & WS_POPUP)) { - DPRINT("No parent for child window\n" ); - return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */ - } -#endif - classPtr = CLASS_FindClassByAtom(classAtom,cs->hInstance); - if ( classPtr == NULL ) - return NULL; - - - if (!(wndPtr = HeapAlloc(GetProcessHeap(),0, sizeof(WND) + classPtr->cbWndExtra - - sizeof(classPtr->wExtra) ))) - { - return NULL; - } - - - - wndPtr->next = rootWnd; - rootWnd = wndPtr; - - wndPtr->class = classPtr; - - wndPtr->hwndSelf = wndPtr; - - - /* Fill the window structure */ - - wndPtr->next = NULL; - wndPtr->child = NULL; - - if ((cs->style & WS_CHILD) && cs->hwndParent) - { - wndPtr->parent = WIN_FindWndPtr( cs->hwndParent ); - wndPtr->owner = NULL; - WIN_ReleaseWndPtr(wndPtr->parent); - } - else - { - wndPtr->parent = WIN_GetDesktop(); - if (!cs->hwndParent || (cs->hwndParent == WIN_GetDesktop()->hwndSelf)) - wndPtr->owner = NULL; - else - { - WND *tmpWnd = WIN_FindWndPtr(cs->hwndParent); - wndPtr->owner = WIN_GetTopParentPtr(tmpWnd); - WIN_ReleaseWndPtr(wndPtr->owner); - WIN_ReleaseWndPtr(tmpWnd); - } - } - -/* - else - { - wndPtr->parent = WIN_GetDesktop(); - if (!cs->hWndParent || (cs->hWndParent == WIN_GetDesktop()->hwndSelf)) - wndPtr->owner = NULL; - else - wndPtr->owner = WIN_GetTopParentPtr(WIN_FindWndPtr(cs->hWndParent)); - } - */ - - wndPtr->winproc = classPtr->winproc; - wndPtr->dwMagic = WND_MAGIC; - - wndPtr->hInstance = cs->hInstance; - wndPtr->text = NULL; - wndPtr->hmemTaskQ = GetFastQueue(); - wndPtr->hrgnUpdate = 0; - wndPtr->hwndLastActive = wndPtr->hwndSelf; - wndPtr->dwStyle = cs->style & ~WS_VISIBLE; - wndPtr->dwExStyle = cs->dwExStyle; - wndPtr->wIDmenu = 0; - wndPtr->helpContext = 0; - wndPtr->flags = 0; - wndPtr->pVScroll = NULL; - wndPtr->pHScroll = NULL; - wndPtr->pProp = NULL; - wndPtr->userdata = 0; - wndPtr->hSysMenu = (wndPtr->dwStyle & WS_SYSMENU) - ? MENU_GetSysMenu( wndPtr->hwndSelf, 0 ) : 0; - - if (classPtr->cbWndExtra) - HEAP_memset( wndPtr->wExtra, 0, classPtr->cbWndExtra); - - - /* Call the WH_CBT hook */ - - hWndLinkAfter = ((cs->style & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD) ? HWND_BOTTOM : HWND_TOP; - - if (HOOK_IsHooked( WH_CBT )) - { - CBT_CREATEWNDW cbtc; - LRESULT ret; - - cbtc.lpcs = cs; - cbtc.hwndInsertAfter = hWndLinkAfter; - ret = HOOK_CallHooks(WH_CBT, HCBT_CREATEWND, (INT)wndPtr->hwndSelf, (LPARAM)&cbtc, classPtr->bUnicode); - if (ret) - { - - HeapFree( GetProcessHeap(),0,wndPtr ); - return NULL; - } - } - - /* Increment class window counter */ - - classPtr->cWindows++; - - /* Correct the window style */ - - if (!(cs->style & (WS_POPUP | WS_CHILD))) /* Overlapped window */ - { - wndPtr->dwStyle |= WS_CAPTION | WS_CLIPSIBLINGS; - wndPtr->flags |= WIN_NEED_SIZE; - } - if (cs->dwExStyle & WS_EX_DLGMODALFRAME) - wndPtr->dwStyle &= ~WS_THICKFRAME; - - - - - - GetStartupInfoW((STARTUPINFO *)&StartupInfo); - if (cs->x == CW_USEDEFAULT) - { - if ( !(cs->style & (WS_CHILD | WS_POPUP)) - && (StartupInfo.dwFlags & STARTF_USEPOSITION) ) - { - cs->x = StartupInfo.dwX; - cs->y = StartupInfo.dwY; - } - else - { - cs->x = 0; - cs->y = 0; - } - } - if (cs->cx == CW_USEDEFAULT) - { - - if ( !(cs->style & (WS_CHILD | WS_POPUP)) - && (StartupInfo.dwFlags & STARTF_USESIZE) ) - { - cs->cx = StartupInfo.dwXSize; - cs->cy = StartupInfo.dwYSize; - } - else - { - cs->cx = SYSMETRICS_CXSCREEN; - cs->cy = SYSMETRICS_CYSCREEN; - } - } - - - - - /* Send the WM_GETMINMAXINFO message and fix the size if needed and appropriate */ - - if ( !(cs->style & (WS_POPUP | WS_CHILD) )) { - - if ((cs->style & WS_THICKFRAME) ) - { - - WINPOS_GetMinMaxInfo( wndPtr, &maxSize, &maxPos, &minTrack, &maxTrack); - if (maxSize.x < cs->cx) cs->cx = maxSize.x; - if (maxSize.y < cs->cy) cs->cy = maxSize.y; - if (cs->cx < minTrack.x ) cs->cx = minTrack.x; - if (cs->cy < minTrack.y ) cs->cy = minTrack.y; - - } - - - } - if(cs->style & WS_CHILD) - { - if(cs->cx < 0) cs->cx = 0; - if(cs->cy < 0) cs->cy = 0; - } - else - { - if (cs->cx <= 0) cs->cx = 1; - if (cs->cy <= 0) cs->cy = 1; - } - - wndPtr->rectWindow.left = cs->x; - wndPtr->rectWindow.top = cs->y; - wndPtr->rectWindow.right = cs->x + cs->cx; - wndPtr->rectWindow.bottom = cs->y + cs->cy; - - wndPtr->rectClient= wndPtr->rectWindow; - - - DPRINT(":%d %d %d %d\n", wndPtr->rectWindow.left, wndPtr->rectWindow.top, - wndPtr->rectWindow.right, wndPtr->rectWindow.bottom); - - /* Get class or window DC if needed */ - - if (classPtr->style & CS_OWNDC) - wndPtr->dce = DCE_AllocDCE(wndPtr,DCE_WINDOW_DC); - else if (classPtr->style & CS_CLASSDC) - wndPtr->dce = classPtr->dce; - else if ( classPtr->style & CS_PARENTDC) - wndPtr->dce = wndPtr->parent->dce; - else wndPtr->dce = DCE_AllocDCE(wndPtr,DCE_WINDOW_DC);; - - - //wndPtr->rectClient.top = wndPtr->rectClient.left = 0; - //wndPtr->rectClient.right = wndPtr->rectWindow.right - wndPtr->rectWindow.left; - //wndPtr->rectClient.bottom = wndPtr->rectWindow.bottom - wndPtr->rectWindow.top; - - - /* Set the window menu */ - - if ((wndPtr->dwStyle & (WS_CAPTION | WS_CHILD)) == WS_CAPTION ) - { - if (cs->hMenu) - SetMenu(wndPtr->hwndSelf, cs->hMenu); - else - { - if (classPtr->menuName) { - if ( classPtr->bUnicode == FALSE ) - cs->hMenu = LoadMenuA(cs->hInstance,classPtr->menuName); - else - cs->hMenu = LoadMenuW(cs->hInstance,classPtr->menuName); - } - } - } - else - wndPtr->wIDmenu = (UINT)cs->hMenu; - - /* Send the WM_CREATE message - * Perhaps we shouldn't allow width/height changes as well. - * See p327 in "Internals". - */ - - maxPos.x = wndPtr->rectWindow.left; - maxPos.y = wndPtr->rectWindow.top; - - - if( MSG_SendMessage( wndPtr, WM_NCCREATE, 0, (LPARAM)cs) == 0) - { - /* Abort window creation */ - WIN_DestroyWindow( wndPtr ); - return NULL; - } - - - /* Insert the window in the linked list */ - - WIN_LinkWindow( wndPtr->hwndSelf, hWndLinkAfter ); - - WINPOS_SendNCCalcSize( wndPtr->hwndSelf, FALSE, &wndPtr->rectWindow, - NULL, NULL, 0, &wndPtr->rectClient ); - OffsetRect(&wndPtr->rectWindow, maxPos.x - wndPtr->rectWindow.left, - maxPos.y - wndPtr->rectWindow.top); - - - if( (MSG_SendMessage( wndPtr, WM_CREATE, 0, (LPARAM)cs)) == -1 ) - { - WIN_UnlinkWindow( wndPtr->hwndSelf ); - WIN_DestroyWindow( wndPtr ); - return NULL; - } - /* Send the size messages */ - - if (!(wndPtr->flags & WIN_NEED_SIZE)) - { - /* send it anyway */ - if (((wndPtr->rectClient.right-wndPtr->rectClient.left) <0) - ||((wndPtr->rectClient.bottom-wndPtr->rectClient.top)<0)) - - MSG_SendMessage( wndPtr, WM_SIZE, SIZE_RESTORED, - MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left, - wndPtr->rectClient.bottom-wndPtr->rectClient.top)); - MSG_SendMessage( wndPtr, WM_MOVE, 0, - MAKELONG( wndPtr->rectClient.left, - wndPtr->rectClient.top) ); - } - - /* Show the window, maximizing or minimizing if needed */ - - if (wndPtr->dwStyle & (WS_MINIMIZE | WS_MAXIMIZE)) - { - RECT newPos; - UINT swFlag = (wndPtr->dwStyle & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE; - wndPtr->dwStyle &= ~(WS_MAXIMIZE | WS_MINIMIZE); - WINPOS_MinMaximize( wndPtr, swFlag, &newPos ); - swFlag = ((wndPtr->dwStyle & WS_CHILD) || GetActiveWindow()) - ? SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED - : SWP_NOZORDER | SWP_FRAMECHANGED; - SetWindowPos( wndPtr->hwndSelf, 0, newPos.left, newPos.top, - newPos.right, newPos.bottom, swFlag ); - } - - if( wndPtr->dwStyle & WS_CHILD && !(wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY) ) - { - /* Notify the parent window only */ - - MSG_SendMessage( wndPtr->parent, WM_PARENTNOTIFY, - MAKEWPARAM(WM_CREATE, wndPtr->wIDmenu), (LPARAM)wndPtr->hwndSelf ); - if( !IsWindow(wndPtr->hwndSelf) ) return 0; - } - - if (cs->style & WS_VISIBLE) - ShowWindow( wndPtr->hwndSelf, SW_SHOW ); - - /* Call WH_SHELL hook */ - - if (!(wndPtr->dwStyle & WS_CHILD) && !wndPtr->owner) - HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWCREATED, (INT)wndPtr->hwndSelf, 0L, classPtr->bUnicode); - - return wndPtr->hwndSelf; - - -} - -WINBOOL WIN_IsWindow(HANDLE hWnd) -{ - if (WIN_FindWndPtr( hWnd ) == NULL) return FALSE; - return TRUE; -} - -/*********************************************************************** - * WIN_FindWinToRepaint - * - * Find a window that needs repaint. - */ -HWND WIN_FindWinToRepaint( HWND hwnd, HQUEUE hQueue ) -{ - HWND hwndRet; - WND *pWnd = WIN_GetDesktop(); - - /* Note: the desktop window never gets WM_PAINT messages - * The real reason why is because Windows DesktopWndProc - * does ValidateRgn inside WM_ERASEBKGND handler. - */ - - pWnd = hwnd ? WIN_FindWndPtr( hwnd ) : WIN_GetDesktop()->child; - - for ( ; pWnd ; pWnd = pWnd->next ) - { - if (!(pWnd->dwStyle & WS_VISIBLE)) - { - DPRINT( "skipping window %04x\n", - pWnd->hwndSelf ); - continue; - } - if ((pWnd->hmemTaskQ == hQueue) && - (pWnd->hrgnUpdate || (pWnd->flags & WIN_INTERNAL_PAINT))) break; - - if (pWnd->child ) - if ((hwndRet = WIN_FindWinToRepaint( pWnd->child->hwndSelf, hQueue )) ) - return hwndRet; - } - - if (!pWnd) return 0; - - hwndRet = pWnd->hwndSelf; - - /* look among siblings if we got a transparent window */ - while (pWnd && ((pWnd->dwExStyle & WS_EX_TRANSPARENT) || - !(pWnd->hrgnUpdate || (pWnd->flags & WIN_INTERNAL_PAINT)))) - { - pWnd = pWnd->next; - } - if (pWnd) hwndRet = pWnd->hwndSelf; - DPRINT("found %04x\n",hwndRet); - return hwndRet; -} - -/********************************************************************** - * WIN_GetWindowLong - * - * Helper function for GetWindowLong(). - */ -LONG WIN_GetWindowLong( HWND hwnd, INT offset ) -{ - LONG retval; - WND * wndPtr = WIN_FindWndPtr( hwnd ); - if (!wndPtr) return 0; - if (offset >= 0) - { - if (offset + sizeof(LONG) > wndPtr->class->cbWndExtra) - { - DPRINT( "Invalid offset %d\n", offset ); - return 0; - } - retval = *(LONG *)(((char *)wndPtr->wExtra) + offset); - - return retval; - } - switch(offset) - { - case GWL_USERDATA: return wndPtr->userdata; - case GWL_STYLE: return wndPtr->dwStyle; - case GWL_EXSTYLE: return wndPtr->dwExStyle; - case GWL_ID: return (LONG)wndPtr->wIDmenu; - case GWL_WNDPROC: return (LONG)wndPtr->winproc; - case GWL_HWNDPARENT: return wndPtr->parent ? (LONG)wndPtr->parent->hwndSelf : (LONG)0; - case GWL_HINSTANCE: return (LONG)wndPtr->hInstance; - default: - DPRINT( "Unknown offset %d\n", offset ); - } - return 0; -} - - -/********************************************************************** - * WIN_SetWindowLong - * - * Helper function for SetWindowLong(). - * - * 0 is the failure code. However, in the case of failure SetLastError - * must be set to distinguish between a 0 return value and a failure. - * - * FIXME: The error values for SetLastError may not be right. Can - * someone check with the real thing? - */ -LONG WIN_SetWindowLong( HWND hwnd, INT offset, LONG newval ) -{ - LONG *ptr, retval = 0; - WND * wndPtr = WIN_FindWndPtr( hwnd ); - STYLESTRUCT style; - - //DPRINT("%x=%p %x %lx %x\n",hwnd, wndPtr, offset, newval, type); - - if (!wndPtr) - { - /* Is this the right error? */ - SetLastError( ERROR_INVALID_WINDOW_HANDLE ); - return 0; - } - - if (offset >= 0) - { - if (offset + sizeof(LONG) > wndPtr->class->cbWndExtra) - { - DPRINT( "Invalid offset %d\n", offset ); - - /* Is this the right error? */ - SetLastError( ERROR_OUTOFMEMORY ); - - return 0; - } - ptr = (LONG *)(((char *)wndPtr->wExtra) + offset); - - - /* Special case for dialog window procedure */ - if ((offset == DWL_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG)) - { - retval = (LONG)ptr; - *ptr = newval; - return (LONG)retval; - } - } - else switch(offset) - { - case GWL_ID: - ptr = (LONG*)&wndPtr->wIDmenu; - break; - case GWL_HINSTANCE: - return (LONG)SetWindowWord( hwnd, offset, newval ); - case GWL_WNDPROC: - retval = (LONG)wndPtr->winproc; - wndPtr->winproc = (WNDPROC)newval; - return retval; - case GWL_STYLE: - style.styleOld = wndPtr->dwStyle; - newval &= ~(WS_VISIBLE | WS_CHILD); /* Some bits can't be changed this way */ - style.styleNew = newval | (style.styleOld & (WS_VISIBLE | WS_CHILD)); - - - MSG_SendMessage(wndPtr,WM_STYLECHANGING,GWL_STYLE,(LPARAM)&style); - wndPtr->dwStyle = style.styleNew; - - MSG_SendMessage(wndPtr,WM_STYLECHANGED,GWL_STYLE,(LPARAM)&style); - return style.styleOld; - - case GWL_USERDATA: - ptr = (LONG *)&wndPtr->userdata; - break; - case GWL_EXSTYLE: - style.styleOld = wndPtr->dwExStyle; - style.styleNew = newval; - MSG_SendMessage(wndPtr,WM_STYLECHANGING,GWL_EXSTYLE,(LPARAM)&style); - wndPtr->dwExStyle = newval; - MSG_SendMessage(wndPtr,WM_STYLECHANGED,GWL_EXSTYLE,(LPARAM)&style); - return style.styleOld; - - default: - DPRINT( "Invalid offset %d\n", offset ); - - /* Don't think this is right error but it should do */ - SetLastError( ERROR_OUTOFMEMORY ); - - return 0; - } - retval = *ptr; - *ptr = newval; - return retval; -} - - -/*********************************************************************** - * WIN_DestroyWindow - * - * Destroy storage associated to a window. "Internals" p.358 - */ -WINBOOL WIN_DestroyWindow( WND* wndPtr ) -{ - HWND hWnd; - WND *pWnd; - - if ( wndPtr == NULL ) - return FALSE; - - hWnd = wndPtr->hwndSelf; - - - - /* free child windows */ - - while ((pWnd = wndPtr->child)) - if ( !WIN_DestroyWindow( pWnd ) ) - break; - - MSG_SendMessage( wndPtr, WM_NCDESTROY, 0, 0); - - /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */ - - WINPOS_CheckInternalPos( hWnd ); - if( hWnd == GetCapture()) ReleaseCapture(); - - /* free resources associated with the window */ - -// TIMER_RemoveWindowTimers( wndPtr->hwndSelf ); - PROPERTY_RemoveWindowProps( wndPtr ); - - wndPtr->dwMagic = 0; /* Mark it as invalid */ - - if ((wndPtr->hrgnUpdate) || (wndPtr->flags & WIN_INTERNAL_PAINT)) - { - if ((UINT)wndPtr->hrgnUpdate > 1) - DeleteObject( wndPtr->hrgnUpdate ); - //QUEUE_DecPaintCount( wndPtr->hmemTaskQ ); - } -// changed message queue implementation with pipes - /* toss stale messages from the queue */ -#if 0 - if( wndPtr->hmemTaskQ ) - { - int pos; - WINBOOL bPostQuit = FALSE; - WPARAM wQuitParam = 0; - MESSAGEQUEUE* msgQ = (MESSAGEQUEUE*) GlobalLock(wndPtr->hmemTaskQ); - - while( (pos = QUEUE_FindMsg(msgQ, hWnd, 0, 0)) != -1 ) - { - if( msgQ->messages[pos].msg.message == WM_QUIT ) - { - bPostQuit = TRUE; - wQuitParam = msgQ->messages[pos].msg.wParam; - } - QUEUE_RemoveMsg(msgQ, pos); - } - /* repost WM_QUIT to make sure this app exits its message loop */ - if( bPostQuit ) PostQuitMessage(wQuitParam); - wndPtr->hmemTaskQ = 0; - } -#endif - if (!(wndPtr->dwStyle & WS_CHILD)) - if (wndPtr->wIDmenu) DestroyMenu( (HMENU)wndPtr->wIDmenu ); - if (wndPtr->hSysMenu) DestroyMenu( wndPtr->hSysMenu ); - - - // DeleteDC(wndPtr->dc) /* Always do this to catch orphaned DCs */ - - wndPtr->winproc = NULL; - wndPtr->hwndSelf = NULL; - wndPtr->class->cWindows--; - wndPtr->class = NULL; - pWnd = wndPtr->next; - - //wndPtr->pDriver->pFinalize(wndPtr); - HeapFree( GetProcessHeap(),0,wndPtr ); - return 0; -} - -/*********************************************************************** - * WIN_ResetQueueWindows - * - * Reset the queue of all the children of a given window. - * Return TRUE if something was done. - */ -WINBOOL WIN_ResetQueueWindows( WND* wnd, HQUEUE hQueue, HQUEUE hNew ) -{ - WINBOOL ret = FALSE; - - if (hNew) /* Set a new queue */ - { - for (wnd = wnd->child; (wnd); wnd = wnd->next) - { - if (wnd->hmemTaskQ == hQueue) - { - wnd->hmemTaskQ = hNew; - ret = TRUE; - } - if (wnd->child) - ret |= WIN_ResetQueueWindows( wnd, hQueue, hNew ); - } - } - else /* Queue is being destroyed */ - { - while (wnd->child) - { - WND *tmp = wnd->child; - ret = FALSE; - while (tmp) - { - if (tmp->hmemTaskQ == hQueue) - { - DestroyWindow( tmp->hwndSelf ); - ret = TRUE; - break; - } - if (tmp->child && WIN_ResetQueueWindows(tmp->child,hQueue,0)) - ret = TRUE; - else - tmp = tmp->next; - } - if (!ret) break; - } - } - return ret; -} - -#if 0 - -WND * WIN_FindWndPtr( HWND hWnd ) -{ - WND *wndPtr = rootWnd; - - while ( wndPtr != NULL ) { - if ( wndPtr->hwndSelf == hWnd ) - return wndPtr; - wndPtr->next = wndPtr; - } - return NULL; -} - -#endif - - -#undef WIN_FindWndPtr -WND* WIN_FindWndPtr( HWND hwnd ); -WND * WIN_FindWndPtr( HWND hwnd ) -{ - WND * ptr; - - if ( hwnd == NULL ) return NULL; - ptr = (WND *)( hwnd ); - if (ptr->dwMagic != WND_MAGIC) return NULL; - if (ptr->hwndSelf != hwnd) - { - DPRINT( "Can't happen: hwnd %04x self pointer is %04x\n", - hwnd, ptr->hwndSelf ); - return NULL; - } - return ptr; -} - -WND* WIN_GetDesktop(void) -{ - if ( pWndDesktop == NULL ) - WIN_CreateDesktopWindow(); - return pWndDesktop; -} - -WND **WIN_BuildWinArray( WND *wndPtr, UINT bwaFlags, UINT* pTotal ) -{ - WND **list, **ppWnd; - WND *pWnd; - UINT count, skipOwned, skipHidden; - DWORD skipFlags; - - skipHidden = bwaFlags & BWA_SKIPHIDDEN; - skipOwned = bwaFlags & BWA_SKIPOWNED; - skipFlags = (bwaFlags & BWA_SKIPDISABLED) ? WS_DISABLED : 0; - if( bwaFlags & BWA_SKIPICONIC ) skipFlags |= WS_MINIMIZE; - - /* First count the windows */ - - if (!wndPtr) wndPtr = WIN_GetDesktop(); - for (pWnd = wndPtr->child, count = 0; pWnd; pWnd = pWnd->next) - { - if( (pWnd->dwStyle & skipFlags) || (skipOwned && pWnd->owner) ) continue; - if( !skipHidden || pWnd->dwStyle & WS_VISIBLE ) count++; - } - - if( count ) - { - /* Now build the list of all windows */ - - if ((list = (WND **)HeapAlloc( GetProcessHeap(), 0, sizeof(WND *) * (count + 1)))) - { - for (pWnd = wndPtr->child, ppWnd = list, count = 0; pWnd; pWnd = pWnd->next) - { - if( (pWnd->dwStyle & skipFlags) || (skipOwned && pWnd->owner) ) continue; - if( !skipHidden || pWnd->dwStyle & WS_VISIBLE ) - { - *ppWnd++ = pWnd; - count++; - } - } - *ppWnd = NULL; - } - else count = 0; - } else list = NULL; - - if( pTotal ) *pTotal = count; - return list; -} -void WIN_DestroyList( WND **list ) -{ - HeapFree(GetProcessHeap(),0,*list); -} - - - - - - -/*********************************************************************** - * WIN_UnlinkWindow - * - * Remove a window from the siblings linked list. - */ -WINBOOL WIN_UnlinkWindow( HWND hWnd ) -{ - WND *wndPtr, **ppWnd; - - if (!(wndPtr = WIN_FindWndPtr( hWnd )) || !wndPtr->parent) return FALSE; - ppWnd = &wndPtr->parent->child; - while (*ppWnd != wndPtr) ppWnd = &(*ppWnd)->next; - *ppWnd = wndPtr->next; - return TRUE; -} - - -/*********************************************************************** - * WIN_LinkWindow - * - * Insert a window into the siblings linked list. - * The window is inserted after the specified window, which can also - * be specified as HWND_TOP or HWND_BOTTOM. - */ -WINBOOL WIN_LinkWindow( HWND hWnd, HWND hWndInsertAfter ) -{ - WND *wndPtr, **ppWnd; - - if (!(wndPtr = WIN_FindWndPtr( hWnd )) || !wndPtr->parent) return FALSE; - - if ((hWndInsertAfter == HWND_TOP) || (hWndInsertAfter == HWND_BOTTOM)) - { - ppWnd = &wndPtr->parent->child; /* Point to first sibling hWnd */ - if (hWndInsertAfter == HWND_BOTTOM) /* Find last sibling hWnd */ - while (*ppWnd) ppWnd = &(*ppWnd)->next; - } - else /* Normal case */ - { - WND * afterPtr = WIN_FindWndPtr( hWndInsertAfter ); - if (!afterPtr) return FALSE; - ppWnd = &afterPtr->next; - } - wndPtr->next = *ppWnd; - *ppWnd = wndPtr; - return TRUE; -} - - - -void WIN_UpdateNCArea(WND* wnd, BOOL bUpdate) -{ - POINT pt = {0, 0}; - HRGN hClip = (HRGN)1; - - /* desktop window doesn't have nonclient area */ - if(wnd == WIN_GetDesktop()) - { - wnd->flags &= ~WIN_NEEDS_NCPAINT; - return; - } - - if( wnd->hrgnUpdate > (HRGN)1 ) - { - ClientToScreen(wnd->hwndSelf, &pt); - - hClip = CreateRectRgn( 0, 0, 0, 0 ); - if (!CombineRgn( hClip, wnd->hrgnUpdate, 0, RGN_COPY )) - { - DeleteObject(hClip); - hClip = (HRGN)1; - } - else - OffsetRgn( hClip, pt.x, pt.y ); - - if (bUpdate) - { - /* exclude non-client area from update region */ - HRGN hrgn = CreateRectRgn( 0, 0, - wnd->rectClient.right - wnd->rectClient.left, - wnd->rectClient.bottom - wnd->rectClient.top); - - if (hrgn && (CombineRgn( wnd->hrgnUpdate, wnd->hrgnUpdate, - hrgn, RGN_AND) == NULLREGION)) - { - DeleteObject( wnd->hrgnUpdate ); - wnd->hrgnUpdate = (HRGN)1; - } - - DeleteObject( hrgn ); - } - } - - wnd->flags &= ~WIN_NEEDS_NCPAINT; - -#ifdef OPTIMIZE - if ((wnd->hwndSelf == GetActiveWindow()) && - !(wnd->flags & WIN_NCACTIVATED)) - { - wnd->flags |= WIN_NCACTIVATED; - if( hClip > (HRGN)1) DeleteObject( hClip ); - hClip = (HRGN)1; - } -#endif - - if (hClip) MSG_SendMessage( wnd, WM_NCPAINT, (WPARAM)hClip, 0L ); - - if (hClip > (HRGN)1) DeleteObject( hClip ); -} - -/*********************************************************************** - * WIN_IsWindowDrawable - * - * hwnd is drawable when it is visible, all parents are not - * minimized, and it is itself not minimized unless we are - * trying to draw its default class icon. - */ -WINBOOL WIN_IsWindowDrawable( WND* wnd, WINBOOL icon ) -{ - - return TRUE; - - if ( wnd == NULL ) - return FALSE; - if( (wnd->dwStyle & WS_MINIMIZE && - icon && wnd->class->hIcon) || - !(wnd->dwStyle & WS_VISIBLE) ) return FALSE; - for(wnd = wnd->parent; wnd; wnd = wnd->parent) - if( wnd->dwStyle & WS_MINIMIZE || - !(wnd->dwStyle & WS_VISIBLE) ) break; - return wnd == NULL; -} - - - -WND* WIN_GetTopParentPtr( WND* pWnd ) -{ - while( pWnd && (pWnd->dwStyle & WS_CHILD)) pWnd = pWnd->parent; - return pWnd; -} - - -HWND WIN_GetTopParent( HWND hwnd ) -{ - WND *wndPtr = WIN_GetTopParentPtr ( WIN_FindWndPtr( hwnd ) ); - return wndPtr ? wndPtr->hwndSelf : 0; -} - - -void WIN_CheckFocus( WND* pWnd ) -{ - if( GetFocus() == pWnd->hwndSelf ) - SetFocus( (pWnd->dwStyle & WS_CHILD) ? pWnd->parent->hwndSelf : 0 ); -} - - -void WIN_SendDestroyMsg( WND* pWnd ) -{ - WIN_CheckFocus(pWnd); - - if( CARET_GetHwnd() == pWnd->hwndSelf ) DestroyCaret(); - - - MSG_SendMessage( pWnd, WM_DESTROY, 0, 0); - - if( IsWindow(pWnd->hwndSelf) ) - { - WND* pChild = pWnd->child; - while( pChild ) - { - WIN_SendDestroyMsg( pChild ); - pChild = pChild->next; - } - WIN_CheckFocus(pWnd); - } - else - DPRINT( "\tdestroyed itself while in WM_DESTROY!\n"); -} - - -/*********************************************************************** - * IsDialogMessage (USER32.90) - */ -WINBOOL STDCALL WIN_IsDialogMessage( HWND hwndDlg, LPMSG msg ) -{ - - WINBOOL ret, translate, dispatch; - INT dlgCode; - - if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) - return FALSE; - - dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, (LPARAM)msg); - ret = DIALOG_IsDialogMessage( msg->hwnd, hwndDlg, msg->message, - msg->wParam, msg->lParam, - &translate, &dispatch, dlgCode ); - if (translate) TranslateMessage( msg ); - if (dispatch) DispatchMessage( msg ); - return ret; -} - - -WINBOOL WIN_GetClientRect(WND *wndPtr, LPRECT lpRect ) -{ - if ( lpRect == NULL ) - return FALSE; - lpRect->left = lpRect->top = lpRect->right = lpRect->bottom = 0; - if (wndPtr) - { - lpRect->right = wndPtr->rectClient.right - wndPtr->rectClient.left; - lpRect->bottom = wndPtr->rectClient.bottom - wndPtr->rectClient.top; - } - return TRUE; -} - -/*********************************************************************** - * WIN_LockWndPtr - * - * Use in case the wnd ptr is not initialized with WIN_FindWndPtr - * but by initWndPtr; - * Returns the locked initialisation pointer - */ -WND *WIN_LockWndPtr(WND *initWndPtr) -{ - if(!initWndPtr) return 0; - - return initWndPtr; - -} - - -void WIN_ReleaseWndPtr(WND *wndPtr) -{ - if(!wndPtr) return; -} - -/*********************************************************************** - * WIN_UpdateWndPtr - * - * Updates the value of oldPtr to newPtr. - */ -void WIN_UpdateWndPtr(WND **oldPtr, WND *newPtr) -{ - WND *tmpWnd = NULL; - - tmpWnd = WIN_LockWndPtr(newPtr); - WIN_ReleaseWndPtr(*oldPtr); - *oldPtr = tmpWnd; - -} - -/******************************************************************* - * GetSysModalWindow16 (USER.52) - */ -HWND GetSysModalWindow(void) -{ - return NULL; -} diff --git a/reactos/lib/user32/internal/winpos.c b/reactos/lib/user32/internal/winpos.c deleted file mode 100644 index ae65ffba7af..00000000000 --- a/reactos/lib/user32/internal/winpos.c +++ /dev/null @@ -1,1158 +0,0 @@ -/* - * Window position related functions. - * - * Copyright 1993, 1994, 1995 Alexandre Julliard - * 1995, 1996 Alex Korobka - */ - -#include -#define MIN min -#define MAX max - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -HWND ICONTITLE_Create( WND *pWnd ); -HWND GetSysModalWindow(void); - - -/* ----- internal variables ----- */ -HWND hwndActive = 0; /* Currently active window */ -HWND hwndPrevActive = 0; /* Previously active window */ -HWND hGlobalShellWindow=0; /*the shell*/ - -LPCSTR atomInternalPos; - -HWND WINPOS_GetActiveWindow(void) -{ - return hwndActive; -} - - -/*********************************************************************** - * WINPOS_CreateInternalPosAtom - */ -WINBOOL WINPOS_CreateInternalPosAtom() -{ - LPSTR str = "SysIP"; -atomInternalPos ="SysIP"; - // atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str); - //if ( atomInternalPos == NULL ) -// atomInternalPos = (LPCSTR)(DWORD)GlobalFindAtom(str); - return (atomInternalPos) ? TRUE : FALSE; -} - -/*********************************************************************** - * WINPOS_CheckInternalPos - * - * Called when a window is destroyed. - */ -void WINPOS_CheckInternalPos( HWND hwnd ) -{ - LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos ); - - if( hwnd == hwndPrevActive ) hwndPrevActive = 0; - if( hwnd == hwndActive ) - { - hwndActive = 0; - DPRINT("\tattempt to activate destroyed window!\n"); - } - - if( lpPos ) - { - //if( IsWindow(lpPos->hwndIconTitle) ) - // DestroyWindow( lpPos->hwndIconTitle ); - //HeapFree( GetProcessHeap(), 0, lpPos ); - } -} - -/*********************************************************************** - * WINPOS_FindIconPos - * - * Find a suitable place for an iconic window. - */ -static POINT WINPOS_FindIconPos( WND* wndPtr, POINT pt ) -{ - RECT rectParent; - short x, y, xspacing, yspacing; - - if ( wndPtr->parent != NULL ) { - GetClientRect( wndPtr->parent->hwndSelf, &rectParent ); - } - else { - - rectParent.left = 0; - rectParent.right = SYSMETRICS_CXFULLSCREEN; - - rectParent.top = 0; - rectParent.right = SYSMETRICS_CYFULLSCREEN; - } - - if ((pt.x >= rectParent.left) && (pt.x + SYSMETRICS_CXICON < rectParent.right) && - (pt.y >= rectParent.top) && (pt.y + SYSMETRICS_CYICON < rectParent.bottom)) - return pt; /* The icon already has a suitable position */ - - xspacing = SYSMETRICS_CXICONSPACING; - yspacing = SYSMETRICS_CYICONSPACING; - - y = rectParent.bottom; - for (;;) - { - for (x = rectParent.left; x <= rectParent.right-xspacing; x += xspacing) - { - /* Check if another icon already occupies this spot */ - WND *childPtr = NULL; - if ( wndPtr->parent ) - childPtr = wndPtr->parent->child; - while (childPtr) - { - if ((childPtr->dwStyle & WS_MINIMIZE) && (childPtr != wndPtr)) - { - if ((childPtr->rectWindow.left < x + xspacing) && - (childPtr->rectWindow.right >= x) && - (childPtr->rectWindow.top <= y) && - (childPtr->rectWindow.bottom > y - yspacing)) - break; /* There's a window in there */ - } - childPtr = childPtr->next; - } - if (!childPtr) /* No window was found, so it's OK for us */ - { - pt.x = x + (xspacing - SYSMETRICS_CXICON) / 2; - pt.y = y - (yspacing + SYSMETRICS_CYICON) / 2; - return pt; - } - } - y -= yspacing; - } -} - -/*********************************************************************** - * WINPOS_WindowFromPoint - * - * Find the window and hittest for a given point. - */ -INT WINPOS_WindowFromPoint( WND* wndScope, POINT pt, WND **ppWnd ) -{ - WND *wndPtr; - INT hittest = HTERROR; - POINT xy = pt; - - *ppWnd = NULL; - wndPtr = wndScope->child; - //if( wndScope->flags & WIN_MANAGED ) - { - /* this prevents mouse clicks from going "through" scrollbars in managed mode */ - if( pt.x < wndScope->rectClient.left || pt.x >= wndScope->rectClient.right || - pt.y < wndScope->rectClient.top || pt.y >= wndScope->rectClient.bottom ) - goto hittest; - } - MapWindowPoints( GetDesktopWindow(), wndScope->hwndSelf, &xy, 1 ); - - for (;;) - { - while (wndPtr) - { - /* If point is in window, and window is visible, and it */ - /* is enabled (or it's a top-level window), then explore */ - /* its children. Otherwise, go to the next window. */ - - if ((wndPtr->dwStyle & WS_VISIBLE) && - (!(wndPtr->dwStyle & WS_DISABLED) || - ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) != WS_CHILD)) && - (xy.x >= wndPtr->rectWindow.left) && - (xy.x < wndPtr->rectWindow.right) && - (xy.y >= wndPtr->rectWindow.top) && - (xy.y < wndPtr->rectWindow.bottom)) - { - *ppWnd = wndPtr; /* Got a suitable window */ - - /* If window is minimized or disabled, return at once */ - if (wndPtr->dwStyle & WS_MINIMIZE) return HTCAPTION; - if (wndPtr->dwStyle & WS_DISABLED) return HTERROR; - - /* If point is not in client area, ignore the children */ - if ((xy.x < wndPtr->rectClient.left) || - (xy.x >= wndPtr->rectClient.right) || - (xy.y < wndPtr->rectClient.top) || - (xy.y >= wndPtr->rectClient.bottom)) break; - - xy.x -= wndPtr->rectClient.left; - xy.y -= wndPtr->rectClient.top; - wndPtr = wndPtr->child; - } - else wndPtr = wndPtr->next; - } - -hittest: - /* If nothing found, try the scope window */ - if (!*ppWnd) *ppWnd = wndScope; - - /* Send the WM_NCHITTEST message (only if to the same task) */ - if ((*ppWnd)->hmemTaskQ == GetFastQueue()) - { - hittest = (INT)SendMessageA( (*ppWnd)->hwndSelf, WM_NCHITTEST, - 0, MAKELONG( pt.x, pt.y ) ); - if (hittest != HTTRANSPARENT) return hittest; /* Found the window */ - } - else return HTCLIENT; - - /* If no children found in last search, make point relative to parent */ - if (!wndPtr) - { - xy.x += (*ppWnd)->rectClient.left; - xy.y += (*ppWnd)->rectClient.top; - } - - /* Restart the search from the next sibling */ - wndPtr = (*ppWnd)->next; - *ppWnd = (*ppWnd)->parent; - } -} - -/******************************************************************* - * WINPOS_GetWinOffset - * - * Calculate the offset between the origin of the two windows. Used - * to implement MapWindowPoints. - */ -void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, - POINT *offset ) -{ - WND * wndPtr; - - offset->x = offset->y = 0; - if (hwndFrom == hwndTo ) return; - - /* Translate source window origin to screen coords */ - if (hwndFrom) - { - if (!(wndPtr = WIN_FindWndPtr( hwndFrom ))) - { - //ERR(win,"bad hwndFrom = %04x\n",hwndFrom); - return; - } - while (wndPtr->parent) - { - offset->x += wndPtr->rectClient.left; - offset->y += wndPtr->rectClient.top; - wndPtr = wndPtr->parent; - } - } - - /* Translate origin to destination window coords */ - if (hwndTo) - { - if (!(wndPtr = WIN_FindWndPtr( hwndTo ))) - { - //ERR(win,"bad hwndTo = %04x\n", hwndTo ); - return; - } - while (wndPtr->parent) - { - offset->x -= wndPtr->rectClient.left; - offset->y -= wndPtr->rectClient.top; - wndPtr = wndPtr->parent; - } - } -} - -/******************************************************************* - * WINPOS_CanActivate - */ -WINBOOL WINPOS_CanActivate(WND* pWnd) -{ - if( pWnd && ((pWnd->dwStyle & (WS_DISABLED | WS_VISIBLE | WS_CHILD)) - == WS_VISIBLE) ) return TRUE; - return FALSE; -} - -/*********************************************************************** - * WINPOS_InitInternalPos - */ -LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, - LPRECT restoreRect ) -{ - LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf, - atomInternalPos ); - if( !lpPos ) - { - /* this happens when the window is minimized/maximized - * for the first time (rectWindow is not adjusted yet) */ - - lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) ); - if( !lpPos ) return NULL; - - SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos ); - lpPos->hwndIconTitle = 0; /* defer until needs to be shown */ - memcpy( &lpPos->rectNormal, &wnd->rectWindow ,sizeof(RECT)); - *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF; - } - - - if( wnd->dwStyle & WS_MINIMIZE ) - memcpy( &lpPos->ptIconPos, &pt,sizeof(POINT) ); - else if( wnd->dwStyle & WS_MAXIMIZE ) - memcpy( &lpPos->ptMaxPos, &pt,sizeof(POINT) ); - else if( restoreRect ) - memcpy( &lpPos->rectNormal, restoreRect, sizeof(RECT) ); - - return lpPos; -} - -/*********************************************************************** - * WINPOS_RedrawIconTitle - */ -WINBOOL WINPOS_RedrawIconTitle( HWND hWnd ) -{ - LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos ); - if( lpPos ) - { - if( lpPos->hwndIconTitle ) - { - SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0); - InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE ); - return TRUE; - } - } - return FALSE; -} - -/*********************************************************************** - * WINPOS_ShowIconTitle - */ -WINBOOL WINPOS_ShowIconTitle( WND* pWnd, WINBOOL bShow ) -{ - LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( pWnd->hwndSelf, atomInternalPos ); - - if( lpPos ) - { - HWND hWnd = lpPos->hwndIconTitle; - - //DPRINT("0x%04x %i\n", pWnd->hwndSelf, (bShow != 0) ); - - if( !hWnd ) - lpPos->hwndIconTitle = hWnd = ICONTITLE_Create( pWnd ); - if( bShow ) - { - pWnd = WIN_FindWndPtr(hWnd); - - if( !(pWnd->dwStyle & WS_VISIBLE) ) - { - SendMessageA( hWnd, WM_SHOWWINDOW, TRUE, 0 ); - SetWindowPos( hWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | - SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW ); - } - } - else ShowWindow( hWnd, SW_HIDE ); - } - return FALSE; -} - -/******************************************************************* - * WINPOS_GetMinMaxInfo - * - * Get the minimized and maximized information for a window. - */ -void WINPOS_GetMinMaxInfo( WND *wndPtr, POINT *maxSize, POINT *maxPos, - POINT *minTrack, POINT *maxTrack ) -{ - LPINTERNALPOS lpPos; - MINMAXINFO MinMax; - INT xinc, yinc; - - /* Compute default values */ - - MinMax.ptMaxSize.x = SYSMETRICS_CXSCREEN; - MinMax.ptMaxSize.y = SYSMETRICS_CYSCREEN; - MinMax.ptMinTrackSize.x = SYSMETRICS_CXMINTRACK; - MinMax.ptMinTrackSize.y = SYSMETRICS_CYMINTRACK; - MinMax.ptMaxTrackSize.x = SYSMETRICS_CXSCREEN; - MinMax.ptMaxTrackSize.y = SYSMETRICS_CYSCREEN; - - //if (wndPtr->flags & WIN_MANAGED) - xinc = yinc = 0; - //else - if (HAS_DLGFRAME( wndPtr->dwStyle, wndPtr->dwExStyle )) - { - xinc = SYSMETRICS_CXDLGFRAME; - yinc = SYSMETRICS_CYDLGFRAME; - } - else - { - xinc = yinc = 0; - if (HAS_THICKFRAME(wndPtr->dwStyle)) - { - xinc += SYSMETRICS_CXFRAME; - yinc += SYSMETRICS_CYFRAME; - } - if (wndPtr->dwStyle & WS_BORDER) - { - xinc += SYSMETRICS_CXBORDER; - yinc += SYSMETRICS_CYBORDER; - } - } - MinMax.ptMaxSize.x += 2 * xinc; - MinMax.ptMaxSize.y += 2 * yinc; - - lpPos = (LPINTERNALPOS)GetPropA( wndPtr->hwndSelf, atomInternalPos ); - if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) ) - memcpy( &MinMax.ptMaxPosition, &lpPos->ptMaxPos,sizeof(POINT) ); - else - { - MinMax.ptMaxPosition.x = -xinc; - MinMax.ptMaxPosition.y = -yinc; - } - - MSG_SendMessage( wndPtr, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax ); - - /* Some sanity checks */ - - - MinMax.ptMaxTrackSize.x = MAX( MinMax.ptMaxTrackSize.x, - MinMax.ptMinTrackSize.x ); - MinMax.ptMaxTrackSize.y = MAX( MinMax.ptMaxTrackSize.y, - MinMax.ptMinTrackSize.y ); - - if (maxSize) *maxSize = MinMax.ptMaxSize; - if (maxPos) *maxPos = MinMax.ptMaxPosition; - if (minTrack) *minTrack = MinMax.ptMinTrackSize; - if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize; -} - -/*********************************************************************** - * WINPOS_MinMaximize - * - * Fill in lpRect and return additional flags to be used with SetWindowPos(). - * This function assumes that 'cmd' is different from the current window - * state. - */ -UINT WINPOS_MinMaximize( WND* wndPtr, UINT cmd, LPRECT lpRect ) -{ - UINT swpFlags = 0; - POINT size = { wndPtr->rectWindow.left, wndPtr->rectWindow.top }; - LPINTERNALPOS lpPos = WINPOS_InitInternalPos( wndPtr, size, - &wndPtr->rectWindow ); - - - //DPRINT("0x%04x %u\n", wndPtr->hwndSelf, cmd ); - - - if (HOOK_CallHooks(WH_CBT, HCBT_MINMAX, (INT)wndPtr->hwndSelf, cmd, wndPtr->class->bUnicode )) { - swpFlags |= SWP_NOSIZE | SWP_NOMOVE; - return swpFlags; - } - - - - if (lpPos) - { - if( wndPtr->dwStyle & WS_MINIMIZE ) - { - if( !MSG_SendMessage( wndPtr->hwndSelf, WM_QUERYOPEN, 0, 0L ) ) - return (SWP_NOSIZE | SWP_NOMOVE); - swpFlags |= SWP_NOCOPYBITS; - } - switch( cmd ) - { - case SW_MINIMIZE: - if( wndPtr->dwStyle & WS_MAXIMIZE) - { - wndPtr->flags |= WIN_RESTORE_MAX; - wndPtr->dwStyle &= ~WS_MAXIMIZE; - } - else - wndPtr->flags &= ~WIN_RESTORE_MAX; - wndPtr->dwStyle |= WS_MINIMIZE; - - lpPos->ptIconPos = WINPOS_FindIconPos( wndPtr, lpPos->ptIconPos ); - - SetRect( lpRect, lpPos->ptIconPos.x, lpPos->ptIconPos.y, - SYSMETRICS_CXICON, SYSMETRICS_CYICON ); - swpFlags |= SWP_NOCOPYBITS; - break; - - case SW_MAXIMIZE: - - WINPOS_GetMinMaxInfo( wndPtr, &size, &lpPos->ptMaxPos, NULL, NULL ); - - if( wndPtr->dwStyle & WS_MINIMIZE ) - { - WINPOS_ShowIconTitle( wndPtr, FALSE ); - wndPtr->dwStyle &= ~WS_MINIMIZE; - } - wndPtr->dwStyle |= WS_MAXIMIZE; - - SetRect( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, - size.x, size.y ); - break; - - case SW_RESTORE: - if( wndPtr->dwStyle & WS_MINIMIZE ) - { - wndPtr->dwStyle &= ~WS_MINIMIZE; - WINPOS_ShowIconTitle( wndPtr, FALSE ); - if( wndPtr->flags & WIN_RESTORE_MAX) - { - /* Restore to maximized position */ - WINPOS_GetMinMaxInfo( wndPtr, &size,&lpPos->ptMaxPos, NULL, NULL); - wndPtr->dwStyle |= WS_MAXIMIZE; - SetRect( lpRect, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, size.x, size.y ); - break; - } - } - else - if( !(wndPtr->dwStyle & WS_MAXIMIZE) ) return (UINT)(-1); - else wndPtr->dwStyle &= ~WS_MAXIMIZE; - - /* Restore to normal position */ - - *lpRect = lpPos->rectNormal; - lpRect->right -= lpRect->left; - lpRect->bottom -= lpRect->top; - - break; - } - } else swpFlags |= SWP_NOSIZE | SWP_NOMOVE; - return swpFlags; -} - -/*********************************************************************** - * WINPOS_SetPlacement - */ -WINBOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, - UINT flags ) -{ - WND *pWnd = WIN_FindWndPtr( hwnd ); - if( pWnd ) - { - LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd, - *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow ); - - if( flags & PLACE_MIN ) lpPos->ptIconPos = wndpl->ptMinPosition; - if( flags & PLACE_MAX ) lpPos->ptMaxPos = wndpl->ptMaxPosition; - if( flags & PLACE_RECT) lpPos->rectNormal = wndpl->rcNormalPosition; - - if( pWnd->dwStyle & WS_MINIMIZE ) - { - WINPOS_ShowIconTitle( pWnd, FALSE ); - if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos)) - SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y, - 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ); - } - else if( pWnd->dwStyle & WS_MAXIMIZE ) - { - if( !EMPTYPOINT(lpPos->ptMaxPos) ) - SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y, - 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ); - } - else if( flags & PLACE_RECT ) - SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top, - lpPos->rectNormal.right - lpPos->rectNormal.left, - lpPos->rectNormal.bottom - lpPos->rectNormal.top, - SWP_NOZORDER | SWP_NOACTIVATE ); - - ShowWindow( hwnd, wndpl->showCmd ); - if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE ) - { - if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd, TRUE ); - - /* SDK: ...valid only the next time... */ - if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX; - } - return TRUE; - } - return FALSE; -} - -/******************************************************************* - * WINPOS_SetActiveWindow - * - * SetActiveWindow() back-end. This is the only function that - * can assign active status to a window. It must be called only - * for the top level windows. - */ -WINBOOL WINPOS_SetActiveWindow( HWND hWnd, WINBOOL fMouse, WINBOOL fChangeFocus) -{ - //CBTACTIVATESTRUCT* cbtStruct; - WND* wndPtr, *wndTemp; - //HQUEUE hOldActiveQueue, hNewActiveQueue; - WORD wIconized = 0; - - /* paranoid checks */ - if( hWnd == GetDesktopWindow || hWnd == hwndActive ) return 0; - -/* if (wndPtr && (GetFastQueue() != wndPtr->hmemTaskQ)) - * return 0; - */ - wndPtr = WIN_FindWndPtr(hWnd); - //hOldActiveQueue = (pActiveQueue)?pActiveQueue->self : 0; - - if( (wndTemp = WIN_FindWndPtr(hwndActive)) ) - wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE); - - -#if 0 - /* call CBT hook chain */ - if ((cbtStruct = SEGPTR_NEW(CBTACTIVATESTRUCT16))) - { - LRESULT wRet; - cbtStruct->fMouse = fMouse; - cbtStruct->hWndActive = hwndActive; - wRet = HOOK_CallHooks16( WH_CBT, HCBT_ACTIVATE, (WPARAM16)hWnd, - (LPARAM)SEGPTR_GET(cbtStruct) ); - SEGPTR_FREE(cbtStruct); - if (wRet) return wRet; - } -#endif - - /* set prev active wnd to current active wnd and send notification */ - if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive)) - { - if (!SendMessageA( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 )) - { - //if (GetSysModalWindow16() != hWnd) return 0; - /* disregard refusal if hWnd is sysmodal */ - } - - - SendMessageA( hwndPrevActive, WM_ACTIVATE, - MAKEWPARAM( WA_INACTIVE, wIconized ), - (LPARAM)hWnd ); - - - /* check if something happened during message processing */ - if( hwndPrevActive != hwndActive ) return 0; - } - - /* set active wnd */ - hwndActive = hWnd; - - /* send palette messages */ - if (hWnd && SendMessage( hWnd, WM_QUERYNEWPALETTE, 0, 0L)) - SendMessage((HWND)-1, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0L ); - - /* if prev wnd is minimized redraw icon title */ - if( IsIconic( hwndPrevActive ) ) WINPOS_RedrawIconTitle(hwndPrevActive); - -#if DESKTOP - /* managed windows will get ConfigureNotify event */ - if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->flags & WIN_MANAGED)) - { - /* check Z-order and bring hWnd to the top */ - for (wndTemp = WIN_GetDesktop()->child; wndTemp; wndTemp = wndTemp->next) - if (wndTemp->dwStyle & WS_VISIBLE) break; - - if( wndTemp != wndPtr ) - SetWindowPos(hWnd, HWND_TOP, 0,0,0,0, - SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE ); - if (!IsWindow(hWnd)) return 0; - } - -#endif - -#if 0 - hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0; - - /* send WM_ACTIVATEAPP if necessary */ - if (hOldActiveQueue != hNewActiveQueue) - { - WND **list, **ppWnd; - - if ((list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) - { - for (ppWnd = list; *ppWnd; ppWnd++) - { - if (!IsWindow( (*ppWnd)->hwndSelf )) continue; - - if ((*ppWnd)->hmemTaskQ == hOldActiveQueue) - SendMessage16( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP, - 0, QUEUE_GetQueueTask(hNewActiveQueue) ); - } - HeapFree( SystemHeap, 0, list ); - } - - pActiveQueue = (hNewActiveQueue) - ? (MESSAGEQUEUE*) GlobalLock16(hNewActiveQueue) : NULL; - - if ((list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL ))) - { - for (ppWnd = list; *ppWnd; ppWnd++) - { - if (!IsWindow( (*ppWnd)->hwndSelf )) continue; - - if ((*ppWnd)->hmemTaskQ == hNewActiveQueue) - SendMessage( (*ppWnd)->hwndSelf, WM_ACTIVATEAPP, - 1, QUEUE_GetQueueTask( hOldActiveQueue ) ); - } - HeapFree( SystemHeap, 0, list ); - } - if (!IsWindow(hWnd)) return 0; - } - -#endif - if (hWnd) - { - /* walk up to the first unowned window */ - wndTemp = wndPtr; - while (wndTemp->owner) wndTemp = wndTemp->owner; - /* and set last active owned popup */ - wndTemp->hwndLastActive = hWnd; - - wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE); - SendMessageA( hWnd, WM_NCACTIVATE, TRUE, 0 ); - - SendMessageA( hWnd, WM_ACTIVATE, - MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized), - (LPARAM)hwndPrevActive ); - - - if( !IsWindow(hWnd) ) return 0; - } -#if 0 - /* change focus if possible */ - if( fChangeFocus && GetFocus() ) - if( WIN_GetTopParent(GetFocus()) != hwndActive ) - FOCUS_SwitchFocus( GetFocus(), - (wndPtr && (wndPtr->dwStyle & WS_MINIMIZE))? - 0: - hwndActive - ); -#endif - - /* if active wnd is minimized redraw icon title */ - if( IsIconic(hwndActive) ) WINPOS_RedrawIconTitle(hwndActive); - - return (hWnd == hwndActive); -} - -/******************************************************************* - * WINPOS_ActivateOtherWindow - * - * Activates window other than pWnd. - */ -WINBOOL WINPOS_ActivateOtherWindow(WND* pWnd) -{ - WINBOOL bRet = 0; - WND* pWndTo = NULL; - - if( pWnd->hwndSelf == hwndPrevActive ) - hwndPrevActive = 0; - - if( hwndActive != pWnd->hwndSelf && - ( hwndActive || QUEUE_IsExitingQueue(pWnd->hmemTaskQ)) ) - return 0; - - if( !(pWnd->dwStyle & WS_POPUP) || !(pWnd->owner) || - !WINPOS_CanActivate((pWndTo = WIN_GetTopParentPtr(pWnd->owner))) ) - { - WND* pWndPtr = WIN_GetTopParentPtr(pWnd); - - pWndTo = WIN_FindWndPtr(hwndPrevActive); - - while( !WINPOS_CanActivate(pWndTo) ) - { - /* by now owned windows should've been taken care of */ - - pWndTo = pWndPtr->next; - pWndPtr = pWndTo; - if( !pWndTo ) break; - } - } - - bRet = WINPOS_SetActiveWindow( pWndTo ? pWndTo->hwndSelf : NULL, FALSE, TRUE ); - - /* switch desktop queue to current active */ - if( pWndTo ) WIN_GetDesktop()->hmemTaskQ = pWndTo->hmemTaskQ; - - hwndPrevActive = 0; - return bRet; -} - -/******************************************************************* - * WINPOS_ChangeActiveWindow - * - */ -WINBOOL WINPOS_ChangeActiveWindow( HWND hWnd, WINBOOL mouseMsg ) -{ - WND *wndPtr = WIN_FindWndPtr(hWnd); - - if (!hWnd) return WINPOS_SetActiveWindow( 0, mouseMsg, TRUE ); - - if( !wndPtr ) return FALSE; - - /* child windows get WM_CHILDACTIVATE message */ - if( (wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD ) - return MSG_SendMessage(wndPtr, WM_CHILDACTIVATE, 0, 0L); - - /* owned popups imply owner activation - not sure */ - if ((wndPtr->dwStyle & WS_POPUP) && wndPtr->owner && - (wndPtr->owner->dwStyle & WS_VISIBLE ) && - !(wndPtr->owner->dwStyle & WS_DISABLED )) - { - if (!(wndPtr = wndPtr->owner)) return FALSE; - hWnd = wndPtr->hwndSelf; - } - - if( hWnd == hwndActive ) return FALSE; - - if( !WINPOS_SetActiveWindow(hWnd ,mouseMsg ,TRUE) ) - return FALSE; - -#if DESKTOP - /* switch desktop queue to current active */ - if( wndPtr->parent == WIN_GetDesktop()) - WIN_GetDesktop()->hmemTaskQ = wndPtr->hmemTaskQ; -#endif - return TRUE; -} - - -/*********************************************************************** - * WINPOS_SendNCCalcSize - * - * Send a WM_NCCALCSIZE message to a window. - * All parameters are read-only except newClientRect. - * oldWindowRect, oldClientRect and winpos must be non-NULL only - * when calcValidRect is TRUE. - */ -LONG WINPOS_SendNCCalcSize( HWND hwnd, WINBOOL calcValidRect, - RECT *newWindowRect, RECT *oldWindowRect, - RECT *oldClientRect, WINDOWPOS *winpos, - RECT *newClientRect ) -{ - NCCALCSIZE_PARAMS params; - WINDOWPOS winposCopy; - LONG result; - - params.rgrc[0] = *newWindowRect; - if (calcValidRect) - { - winposCopy = *winpos; - params.rgrc[1] = *oldWindowRect; - params.rgrc[2] = *oldClientRect; - params.lppos = &winposCopy; - } - result = SendMessageA( hwnd, WM_NCCALCSIZE, calcValidRect, - (LPARAM)¶ms ); - - *newClientRect = params.rgrc[0]; - return result; -} - - -/*********************************************************************** - * WINPOS_HandleWindowPosChanging - * - * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc(). - */ -LONG WINPOS_HandleWindowPosChangingA( WND *wndPtr, WINDOWPOS *winpos ) -{ - POINT maxSize, minTrack; - if (winpos->flags & SWP_NOSIZE) return 0; - if ((wndPtr->dwStyle & WS_THICKFRAME) || - ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0)) - { - WINPOS_GetMinMaxInfo( wndPtr, &maxSize, NULL, &minTrack, NULL ); - if (maxSize.x < winpos->cx) winpos->cx = maxSize.x; - if (maxSize.y < winpos->cy) winpos->cy = maxSize.y; - if (!(wndPtr->dwStyle & WS_MINIMIZE)) - { - if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x; - if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y; - } - } - return 0; -} - - -/*********************************************************************** - * WINPOS_HandleWindowPosChanging - * - * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc(). - */ -LONG WINPOS_HandleWindowPosChanging( WND *wndPtr, WINDOWPOS *winpos ) -{ - POINT maxSize; - if (winpos->flags & SWP_NOSIZE) return 0; - if ((wndPtr->dwStyle & WS_THICKFRAME) || - ((wndPtr->dwStyle & (WS_POPUP | WS_CHILD)) == 0)) - { - WINPOS_GetMinMaxInfo( wndPtr, &maxSize, NULL, NULL, NULL ); - winpos->cx = MIN( winpos->cx, maxSize.x ); - winpos->cy = MIN( winpos->cy, maxSize.y ); - } - return 0; -} - - -/*********************************************************************** - * WINPOS_MoveWindowZOrder - * - * Move a window in Z order, invalidating everything that needs it. - * Only necessary for windows without associated X window. - */ -void WINPOS_MoveWindowZOrder( HWND hwnd, HWND hwndAfter ) -{ - WINBOOL movingUp; - WND *pWndAfter, *pWndCur, *wndPtr = WIN_FindWndPtr( hwnd ); - - /* We have two possible cases: - * - The window is moving up: we have to invalidate all areas - * of the window that were covered by other windows - * - The window is moving down: we have to invalidate areas - * of other windows covered by this one. - */ - - if (hwndAfter == HWND_TOP) - { - movingUp = TRUE; - } - else if (hwndAfter == HWND_BOTTOM) - { - if (!wndPtr->next) return; /* Already at the bottom */ - movingUp = FALSE; - } - else - { - if (!(pWndAfter = WIN_FindWndPtr( hwndAfter ))) return; - if (wndPtr->next == pWndAfter) return; /* Already placed right */ - - /* Determine which window we encounter first in Z-order */ - pWndCur = wndPtr->parent->child; - while ((pWndCur != wndPtr) && (pWndCur != pWndAfter)) - pWndCur = pWndCur->next; - movingUp = (pWndCur == pWndAfter); - } - - if (movingUp) - { - WND *pWndPrevAfter = wndPtr->next; - WIN_UnlinkWindow( hwnd ); - WIN_LinkWindow( hwnd, hwndAfter ); - pWndCur = wndPtr->next; - while (pWndCur != pWndPrevAfter) - { - RECT rect = { pWndCur->rectWindow.left, - pWndCur->rectWindow.top, - pWndCur->rectWindow.right, - pWndCur->rectWindow.bottom }; - OffsetRect( &rect, -wndPtr->rectClient.left, - -wndPtr->rectClient.top ); - PAINT_RedrawWindow( hwnd, &rect, 0, RDW_INVALIDATE | RDW_ALLCHILDREN | - RDW_FRAME | RDW_ERASE, 0 ); - pWndCur = pWndCur->next; - } - } - else /* Moving down */ - { - pWndCur = wndPtr->next; - WIN_UnlinkWindow( hwnd ); - WIN_LinkWindow( hwnd, hwndAfter ); - while (pWndCur != wndPtr) - { - RECT rect = { pWndCur->rectWindow.left, - pWndCur->rectWindow.top, - pWndCur->rectWindow.right, - pWndCur->rectWindow.bottom }; - OffsetRect( &rect, -pWndCur->rectClient.left, - -pWndCur->rectClient.top ); - PAINT_RedrawWindow( pWndCur->hwndSelf, &rect, 0, RDW_INVALIDATE | - RDW_ALLCHILDREN | RDW_FRAME | RDW_ERASE, 0 ); - pWndCur = pWndCur->next; - } - } -} - -/*********************************************************************** - * WINPOS_ReorderOwnedPopups - * - * fix Z order taking into account owned popups - - * basically we need to maintain them above the window that owns them - */ -HWND WINPOS_ReorderOwnedPopups(HWND hwndInsertAfter,WND* wndPtr,WORD flags) -{ - WND* w = WIN_GetDesktop()->child; - - if( wndPtr->dwStyle & WS_POPUP && wndPtr->owner ) - { - /* implement "local z-order" between the top and owner window */ - - HWND hwndLocalPrev = HWND_TOP; - - if( hwndInsertAfter != HWND_TOP ) - { - while( w != wndPtr->owner ) - { - if (w != wndPtr) hwndLocalPrev = w->hwndSelf; - if( hwndLocalPrev == hwndInsertAfter ) break; - w = w->next; - } - hwndInsertAfter = hwndLocalPrev; - } - - } - else if( wndPtr->dwStyle & WS_CHILD ) return hwndInsertAfter; - - w = WIN_GetDesktop()->child; - while( w ) - { - if( w == wndPtr ) break; - - if( w->dwStyle & WS_POPUP && w->owner == wndPtr ) - { - SetWindowPos(w->hwndSelf, hwndInsertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | - SWP_NOACTIVATE | SWP_NOSENDCHANGING | SWP_DEFERERASE); - hwndInsertAfter = w->hwndSelf; - } - w = w->next; - } - - return hwndInsertAfter; -} - -/*********************************************************************** - * WINPOS_SizeMoveClean - * - * Make window look nice without excessive repainting - * - * the pain: - * - * visible regions are in window coordinates - * update regions are in window client coordinates - * client and window rectangles are in parent client coordinates - * - * FIXME: Move visible and update regions to the same coordinate system - * (either parent client or window). This is a lot of work though. - */ -UINT WINPOS_SizeMoveClean( WND* Wnd, HRGN oldVisRgn, - LPRECT lpOldWndRect, - LPRECT lpOldClientRect, UINT uFlags ) -{ - HRGN newVisRgn = DCE_GetVisRgn(Wnd->hwndSelf,DCX_WINDOW | DCX_CLIPSIBLINGS); - HRGN dirtyRgn = CreateRectRgn(0,0,0,0); - int other, my; - - - - if( (lpOldWndRect->right - lpOldWndRect->left) != (Wnd->rectWindow.right - Wnd->rectWindow.left) || - (lpOldWndRect->bottom - lpOldWndRect->top) != (Wnd->rectWindow.bottom - Wnd->rectWindow.top) ) - uFlags |= SMC_DRAWFRAME; - - CombineRgn( dirtyRgn, newVisRgn, 0, RGN_COPY); - - if( !(uFlags & SMC_NOCOPY) ) - CombineRgn( newVisRgn, newVisRgn, oldVisRgn, RGN_AND ); - - /* map regions to the parent client area */ - - OffsetRgn( dirtyRgn, Wnd->rectWindow.left, Wnd->rectWindow.top ); - OffsetRgn( oldVisRgn, lpOldWndRect->left, lpOldWndRect->top ); - - /* compute invalidated region outside Wnd - (in client coordinates of the parent window) */ - - other = CombineRgn(dirtyRgn, oldVisRgn, dirtyRgn, RGN_DIFF); - - /* map visible region to the Wnd client area */ - - OffsetRgn( newVisRgn, Wnd->rectWindow.left - Wnd->rectClient.left, - Wnd->rectWindow.top - Wnd->rectClient.top ); - - /* substract previously invalidated region from the Wnd visible region */ - - my = (Wnd->hrgnUpdate > 1) ? CombineRgn( newVisRgn, newVisRgn, - Wnd->hrgnUpdate, RGN_DIFF) - : COMPLEXREGION; - - if( uFlags & SMC_NOCOPY ) /* invalidate Wnd visible region */ - { - if (my != NULLREGION) - PAINT_RedrawWindow( Wnd->hwndSelf, NULL, newVisRgn, RDW_INVALIDATE | - RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN ); - else if(uFlags & SMC_DRAWFRAME) - Wnd->flags |= WIN_NEEDS_NCPAINT; - } - else /* bitblt old client area */ - { - HDC hDC; - int update; - HRGN updateRgn; - int xfrom,yfrom,xto,yto,width,height; - - if( uFlags & SMC_DRAWFRAME ) - { - /* copy only client area, frame will be redrawn anyway */ - - xfrom = lpOldClientRect->left; yfrom = lpOldClientRect->top; - xto = Wnd->rectClient.left; yto = Wnd->rectClient.top; - width = lpOldClientRect->right - xfrom; height = lpOldClientRect->bottom - yfrom; - updateRgn = CreateRectRgn( 0, 0, width, height ); - CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND ); - SetRectRgn( updateRgn, 0, 0, Wnd->rectClient.right - xto, - Wnd->rectClient.bottom - yto ); - } - else - { - xfrom = lpOldWndRect->left; yfrom = lpOldWndRect->top; - xto = Wnd->rectWindow.left; yto = Wnd->rectWindow.top; - width = lpOldWndRect->right - xfrom; height = lpOldWndRect->bottom - yfrom; - updateRgn = CreateRectRgn( xto - Wnd->rectClient.left, - yto - Wnd->rectClient.top, - Wnd->rectWindow.right - Wnd->rectClient.left, - Wnd->rectWindow.bottom - Wnd->rectClient.top ); - } - - CombineRgn( newVisRgn, newVisRgn, updateRgn, RGN_AND ); - - /* substract new visRgn from target rect to get a region that won't be copied */ - - update = CombineRgn( updateRgn, updateRgn, newVisRgn, RGN_DIFF ); - - /* Blt valid bits using parent window DC */ - - if( Wnd->parent && my != NULLREGION && (xfrom != xto || yfrom != yto) ) - { - - /* compute clipping region in parent client coordinates */ - - OffsetRgn( newVisRgn, Wnd->rectClient.left, Wnd->rectClient.top ); - CombineRgn( oldVisRgn, oldVisRgn, newVisRgn, RGN_OR ); - -// REMOVED DCX_KEEPCLIPRGN - - hDC = GetDCEx( Wnd->parent->hwndSelf, oldVisRgn, - DCX_INTERSECTRGN | DCX_CACHE | DCX_CLIPSIBLINGS); - - BitBlt( hDC, xto, yto, width, height, hDC, xfrom, yfrom, SRCCOPY ); - ReleaseDC( Wnd->parent->hwndSelf, hDC); - - } - - if( update != NULLREGION ) - PAINT_RedrawWindow( Wnd->hwndSelf, NULL, updateRgn, RDW_INVALIDATE | - RDW_FRAME | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN ); - else if( uFlags & SMC_DRAWFRAME ) Wnd->flags |= WIN_NEEDS_NCPAINT; - DeleteObject( updateRgn ); - } - - /* erase uncovered areas */ - - if( !(uFlags & SMC_NOPARENTERASE) && (other != NULLREGION ) ) - PAINT_RedrawWindow( Wnd->parent->hwndSelf, NULL, dirtyRgn, - RDW_INVALIDATE | RDW_ALLCHILDREN | RDW_ERASE, RDW_C_USEHRGN ); - DeleteObject(dirtyRgn); - DeleteObject(newVisRgn); - return uFlags; -} - diff --git a/reactos/lib/user32/makefile_rex b/reactos/lib/user32/makefile_rex index ff7f07a2fea..14935ab1337 100644 --- a/reactos/lib/user32/makefile_rex +++ b/reactos/lib/user32/makefile_rex @@ -1,4 +1,4 @@ -# $Id: makefile_rex,v 1.16 2001/05/07 22:03:27 chorns Exp $ +# $Id: makefile_rex,v 1.17 2001/06/12 17:35:43 chorns Exp $ # # ReactOS Operating System # @@ -6,19 +6,27 @@ # PATH_TO_TOP = ../.. -CFLAGS = -I../../include -DDBG +CFLAGS = -I./include -DUNICODE -DDBG TARGET=user32 MISC_OBJECTS = \ + misc/desktop.o \ misc/dllmain.o \ misc/sprintf.o \ misc/stubs.o \ - misc/win32k.o + misc/win32k.o \ + misc/winsta.o + +WINDOWS_OBJECTS = \ + windows/class.o \ + windows/message.o \ + windows/window.o RESOURCE_OBJECT = $(TARGET).coff -OBJECTS = $(MISC_OBJECTS) $(RESOURCE_OBJECT) +OBJECTS = $(MISC_OBJECTS) $(WINDOWS_OBJECTS) \ + $(RESOURCE_OBJECT) LIBS = ../ntdll/ntdll.a \ ../kernel32/kernel32.a \ diff --git a/reactos/lib/user32/misc/bitmap.c b/reactos/lib/user32/misc/bitmap.c deleted file mode 100644 index 39047f605a2..00000000000 --- a/reactos/lib/user32/misc/bitmap.c +++ /dev/null @@ -1,95 +0,0 @@ -#include - -HBITMAP BITMAP_LoadBitmapW(HINSTANCE instance,LPCWSTR name, UINT loadflags); - - - -HBITMAP -STDCALL -LoadBitmapW(HINSTANCE hInstance, LPCWSTR lpBitmapName) -{ - return BITMAP_LoadBitmapW(hInstance, lpBitmapName, 0); -} - -HBITMAP -STDCALL -LoadBitmapA(HINSTANCE hInstance, LPCSTR lpBitmapName) -{ - return CreateBitmap(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CXSMICON), - 1,1, NULL ); - return NULL; -// return BITMAP_LoadBitmap32W(hInstance, lpBitmapName, 0); -} - -HBITMAP BITMAP_LoadBitmapW(HINSTANCE instance,LPCWSTR name, - UINT loadflags) -{ - return CreateBitmap(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CXSMICON), - 1,1, NULL ); -#if 0 - HBITMAP hbitmap = 0; - HDC hdc; - HRSRC hRsrc; - HGLOBAL handle; - char *ptr = NULL; - BITMAPINFO *info, *fix_info=NULL; - HGLOBAL hFix; - int size; - - if (!(loadflags & LR_LOADFROMFILE)) { - if (!instance) /* OEM bitmap */ - { - HDC hdc; - DC *dc; - - if (HIWORD((int)name)) return 0; - hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL ); - dc = DC_GetDCPtr( hdc ); - if(dc->funcs->pLoadOEMResource) - hbitmap = dc->funcs->pLoadOEMResource( LOWORD((int)name), - OEM_BITMAP ); - GDI_HEAP_UNLOCK( hdc ); - DeleteDC( hdc ); - return hbitmap; - } - - if (!(hRsrc = FindResourceW( instance, name, RT_BITMAPW ))) return 0; - if (!(handle = LoadResource( instance, hRsrc ))) return 0; - - if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0; - } - else - { - if (!(ptr = (char *)VIRTUAL_MapFileW( name ))) return 0; - info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER)); - } - size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS); - if ((hFix = GlobalAlloc(0, size))) fix_info=GlobalLock(hFix); - if (fix_info) { - BYTE pix; - - memcpy(fix_info, info, size); - pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS)); - DIB_FixColorsToLoadflags(fix_info, loadflags, pix); - if ((hdc = GetDC(0)) != 0) { - if (loadflags & LR_CREATEDIBSECTION) - hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0); - else { - char *bits = (char *)info + size;; - hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT, - bits, fix_info, DIB_RGB_COLORS ); - } - ReleaseDC( 0, hdc ); - } - GlobalUnlock(hFix); - GlobalFree(hFix); - } - if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr ); - return hbitmap; -#endif -} - - - diff --git a/reactos/lib/user32/misc/cursor.c b/reactos/lib/user32/misc/cursor.c deleted file mode 100644 index 56059628caa..00000000000 --- a/reactos/lib/user32/misc/cursor.c +++ /dev/null @@ -1,34 +0,0 @@ -#include - -/*********************************************************************** - * SetCursor (USER32.472) - * RETURNS: - * A handle to the previous cursor shape. - */ -HCURSOR STDCALL SetCursor( HCURSOR hCursor ) -{ -} - - -int STDCALL ShowCursor(WINBOOL bShow ) -{ -} - -WINBOOL STDCALL SetCursorPos(int x, int y ) -{ -} - -HCURSOR STDCALL LoadCursorA(HINSTANCE hInstance, LPCSTR lpCursorName ) -{ -} - -HCURSOR STDCALL LoadCursorW(HINSTANCE hInstance, LPCWSTR lpCursorName ) -{ -} - -WINBOOL -STDCALL -DestroyCursor( - HCURSOR hCursor) -{ -} \ No newline at end of file diff --git a/reactos/lib/user32/misc/dllmain.c b/reactos/lib/user32/misc/dllmain.c index 7bd7c4e78b5..ccab82b0595 100644 --- a/reactos/lib/user32/misc/dllmain.c +++ b/reactos/lib/user32/misc/dllmain.c @@ -1,4 +1,45 @@ #include +#include + +#ifdef DBG + +/* See debug.h for debug/trace constants */ +DWORD DebugTraceLevel = MIN_TRACE; + +#endif /* DBG */ + +/* To make the linker happy */ +VOID STDCALL KeBugCheck (ULONG BugCheckCode) {} + +HANDLE ProcessHeap; +HWINSTA ProcessWindowStation; + +DWORD +Init(VOID) +{ + DWORD Status; + + ProcessHeap = RtlGetProcessHeap(); + + //ProcessWindowStation = CreateWindowStationW(L"WinStaName",0,GENERIC_ALL,NULL); + //Desktop = CreateDesktopA(NULL,NULL,NULL,0,0,NULL); + + //GdiDllInitialize(NULL, DLL_PROCESS_ATTACH, NULL); + + return Status; +} + +DWORD +Cleanup(VOID) +{ + DWORD Status; + + //CloseWindowStation(ProcessWindowStation); + + //GdiDllInitialize(NULL, DLL_PROCESS_DETACH, NULL); + + return Status; +} INT STDCALL @@ -8,17 +49,19 @@ DllMain( PVOID reserved ) { + D(MAX_TRACE, ("hinstDll (0x%X) dwReason (0x%X)\n", hinstDll, dwReason)); + switch (dwReason) { case DLL_PROCESS_ATTACH: - //WinStation = CreateWindowStationA(NULL,0,GENERIC_ALL,NULL); - //Desktop = CreateDesktopA(NULL,NULL,NULL,0,0,NULL); + Init(); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: + Cleanup(); break; } return(1); diff --git a/reactos/lib/user32/misc/exitwin.c b/reactos/lib/user32/misc/exitwin.c deleted file mode 100644 index b257aecf286..00000000000 --- a/reactos/lib/user32/misc/exitwin.c +++ /dev/null @@ -1,108 +0,0 @@ -/* $Id: exitwin.c,v 1.2 1999/05/15 13:48:38 ea Exp $ - * - * exitwin.c - * - * Copyright (c) 1999 Emanuele Aliberti - * - * -------------------------------------------------------------------- - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this software; see the file COPYING.LIB. If - * not, write to the Free Software Foundation, Inc., 675 Mass Ave, - * Cambridge, MA 02139, USA. - * - * -------------------------------------------------------------------- - * - * ReactOS user32.dll ExitWindows functions. - * - * 19990515 EA Naive implementation. - */ - -#include -#include - - -/*********************************************************************** - * ExitWindowsEx - * - * ARGUMENTS - * uFlags shutdown operation - * EWX_FORCE Processes are killed. - * - * EWX_LOGOFF Caller owned processed are killed. - * - * EWX_POWEROFF Turns off the power. - * - * EWX_REBOOT Restart the system. - * SE_SHUTDOWN_NAME privilege reqired. - * - * EWX_SHUTDOWN Same as EWX_REBOOT, but rebooting. - * SE_SHUTDOWN_NAME privilege reqired. - * - * dwReserved reserved - * - * REVISIONS - * 1999-05-15 EA - */ -BOOL -__stdcall -ExitWindowsEx( - UINT uFlags, - DWORD dwReserved - ) -{ - NTSTATUS rv; - - if (uFlags & ( - EWX_FORCE | - EWX_LOGOFF | - EWX_POWEROFF | - EWX_REBOOT | - EWX_SHUTDOWN - ) - ) { - /* Unknown flag! */ - SetLastError(ERROR_INVALID_FLAG_NUMBER); - return FALSE; - } - /* FIXME: call csrss.exe; - * - * Naive implementation: call the kernel directly. - * This code will be moved in csrss.exe when - * available. - */ - if (EWX_POWEROFF & uFlags) - { - rv = NtShutdownSystem(ShutdownPowerOff); - } - else if (EWX_REBOOT & uFlags) - { - rv = NtShutdownSystem(ShutdownReboot); - } - else if (EWX_SHUTDOWN & uFlags) - { - rv = NtShutdownSystem(ShutdownNoReboot); - } - else - { - /* How to implement others flags semantics? */ - SetLastError(ERROR_INVALID_FLAG_NUMBER); - rv = (NTSTATUS) -1; - } - return NT_SUCCESS(rv) - ? TRUE - : FALSE; -} - - -/* EOF */ diff --git a/reactos/lib/user32/misc/main.c b/reactos/lib/user32/misc/main.c deleted file mode 100644 index 64c7fa83e31..00000000000 --- a/reactos/lib/user32/misc/main.c +++ /dev/null @@ -1,43 +0,0 @@ - -#include -#include - - -LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM, LPARAM); - - -int main(int argc, char **argv) -{ - - - WINPOS_CreateInternalPosAtom(); - SYSCOLOR_Init(); - WIDGETS_Init(); - ICONTITLE_Init(); - DIALOG_Init(); - COMBO_Init(); - MENU_Init(); - - MessageBox(NULL,"xxx","yyyy",MB_OK); - - return 0; - -} - - - - - - -LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam) -{ - switch(message) - { - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hwnd, message, wParam, lParam); - } - return 0; -} diff --git a/reactos/lib/user32/misc/string.c b/reactos/lib/user32/misc/string.c deleted file mode 100644 index 4110db78901..00000000000 --- a/reactos/lib/user32/misc/string.c +++ /dev/null @@ -1,814 +0,0 @@ -/* - * String functions - * - * Copyright 1993 Yngvi Sigurjonsson (yngvi@hafro.is) - * Copyright 1996 Marcus Meissner - */ - -#include -#include -#include -#include -#include - - -/* Funny to divide them between user and kernel. */ - -/* be careful: always use functions from wctype.h if character > 255 */ - -/* - * Unicode case conversion routines ... these should be used where - * toupper/tolower are used for ASCII. - */ - -// bugfix: mutual exclusiveness of -// FORMAT_MESSAGE_FROM_STRING, FORMAT_MESSAGE_FROM_SYSTEM and FORMAT_MESSAGE_FROM_HMODULE -// in FormatMessage - -#define IsDBCSLeadByte(c) FALSE -#define IsDBCSLeadByteEx(c,n) FALSE -#define CopyMemory memcpy -#define lstrlenA strlen -#define lstrlenW wcslen - -DWORD LoadMessageA(HMODULE hModule,DWORD dwMessageId, - DWORD dwLanguageId,LPSTR Buffer,UINT BufSize); -DWORD LoadMessageW(HMODULE hModule,DWORD dwMessageId, - DWORD dwLanguageId,LPWSTR Buffer,UINT BufSize); - - -LPWSTR lstrchrW(LPCWSTR s, INT c); -LPSTR lstrchrA(LPCSTR s, INT c); - - - -LPSTR STDCALL CharNextA(LPCSTR lpsz) -{ - LPSTR next = (LPSTR)lpsz; - if (!*lpsz) - return next; - if (IsDBCSLeadByte( *next )) - next++; - next++; - return next; -} - - -/*********************************************************************** - * CharNextExA (USER.30) - */ -LPSTR STDCALL CharNextExA( WORD codepage, LPCSTR ptr, DWORD flags ) -{ - LPSTR next = (LPSTR)ptr; - if (!*ptr) - return next; - if (IsDBCSLeadByteEx( codepage, *next )) - return next++; - next++; - return next; -} - - - -LPWSTR -STDCALL -CharNextW(LPCWSTR lpsz) -{ - LPWSTR next = (LPWSTR)lpsz; - if (!*lpsz) - return next; - next++; - return next; -} - - -LPSTR STDCALL CharPrevA( LPCSTR start, LPCSTR ptr ) -{ - LPCSTR next; - while (*start && (start < ptr)) - { - next = CharNextA( start ); - if (next >= ptr) - break; - start = next; - } - return (LPSTR)start; -} - - - -LPSTR STDCALL CharPrevExA( WORD codepage, LPCSTR start, LPCSTR ptr, DWORD flags ) -{ - - LPCSTR next; - while (*start && (start < ptr)) - { - next = CharNextExA( codepage, start, flags ); - if (next > ptr) - break; - start = next; - } - return (LPSTR)start; -} - - - - - - -LPWSTR STDCALL CharPrevW(LPCWSTR start,LPCWSTR x) -{ - LPWSTR prev = (LPWSTR)x; - if (x<=start) - return prev; - prev--; - return prev; -} - - -LPSTR STDCALL CharLowerA(LPSTR x) -{ - LPSTR s; - UINT s2; - if (!HIWORD(x)) { - s2 = (UINT)x; - - if (!IsDBCSLeadByte( s2 )) { - if (!IsCharLowerA(s2)) - s2 = s2 - ( 'A' - 'a' ); - return (LPSTR)s2; - } - else { - // should do a multibyte toupper - if (s2 >= 'A' && s2 <= 'Z') - s2 = s2 - ( 'A' - 'a' ); - return (LPSTR)s2; - } - return (LPSTR)x; - } - - s=x; - while (*s) - { - if (!IsDBCSLeadByte( *s )) { - if (!IsCharLowerA(*s)) - *s = *s - ( 'A' - 'a' ); - } - else { - // should do a multibyte toupper - s++; - } - s++; - } - return x; - -} - - -DWORD STDCALL CharLowerBuffA(LPSTR s,DWORD buflen) -{ - DWORD done=0; - - if (!s) - return 0; /* YES */ - while (*s && (buflen--)) - { - if (!IsDBCSLeadByte( *s )) { - if (!IsCharLowerA(*s)) - *s = *s - ( 'A' - 'a' ); - } - else { - // should do a multibyte toupper - s++; - } - s++; - done++; - } - return done; -} - - -DWORD STDCALL CharLowerBuffW(LPWSTR s,DWORD buflen) -{ - DWORD done=0; - - if (!s) - return 0; /* YES */ - while (*s && (buflen--)) - { - if (!IsCharLowerW(*s)) - *s = *s - ( L'A' - L'a' ); - s++; - done++; - } - return done; -} - - -LPWSTR STDCALL CharLowerW(LPWSTR x) -{ - LPWSTR s; - UINT s2; - if (!HIWORD(x)) { - s2 = (UINT)x; - if (!IsCharLowerW(s2)) - s2 = s2 - ( L'A' - L'a' ); - return (LPWSTR)s2; - } - s = x; - while (*s) - { - if (!IsCharLowerW(*s)) - *s = *s - ( L'A' - L'a' ); - s++; - } - return x; -} - - - -LPSTR STDCALL CharUpperA(LPSTR x) -{ - LPSTR s; - UINT s2; - if (!HIWORD(x)) { - s2 = (UINT)x; - - - if (!IsDBCSLeadByte( s2 )) { - if (!IsCharUpperW(s2)) - s2 = s2 + ( 'A' - 'a' ); - return (LPSTR)s2; - } - else { - // should do a multibyte toupper - if (s2 >= 'a' && s2 <= 'z') - s2 = s2 + ( 'A' - 'a' ); - return (LPSTR)s2; - } - return x; - } - - - - s=x; - while (*s) - { - if (!IsDBCSLeadByte( *s )) { - if (!IsCharUpperW(*s)) - *s = *s + ( 'A' - 'a' ); - } - else { - // should do a multibyte toupper - s++; - } - s++; - } - return x; - -} - - -DWORD STDCALL CharUpperBuffA(LPSTR s,DWORD buflen) -{ - DWORD done=0; - - if (!s) - return 0; /* YES */ - while (*s && (buflen--)) - { - if (!IsDBCSLeadByte( *s )) { - if (!IsCharUpperW(*s)) - *s = *s + ( 'A' - 'a' ); - } - else { - // should do a multibyte toupper - s++; - } - s++; - done++; - } - return done; -} - - -DWORD STDCALL CharUpperBuffW(LPWSTR s,DWORD buflen) -{ - DWORD done=0; - - if (!s) - return 0; /* YES */ - while (*s && (buflen--)) - { - if (!IsCharUpperW(*s)) - *s = *s + ( L'A' - L'a' ); - s++; - done++; - } - return done; -} - - -LPWSTR STDCALL CharUpperW(LPWSTR x) -{ - LPWSTR s; - UINT s2; - if (!HIWORD(x)) { - s2 = (UINT)x; - if (!IsCharUpperW(s2)) - s2 = s2 + ( L'A' - L'a' ); - return (LPWSTR)s2; - } - s = x; - while (*s) - { - if (!IsCharUpperW(*s)) - *s = *s + ( L'A' - L'a' ); - s++; - } - return x; -} - - - -WINBOOL STDCALL IsCharAlphaNumericA(CHAR c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')); -} - - -WINBOOL STDCALL IsCharAlphaNumericW(WCHAR c) -{ - return ((c >= L'A' && c <= L'Z') || (c >= L'a' && c <= L'z') || (c >= L'0' && c <= L'9')); -} -WINBOOL STDCALL IsCharAlphaA(CHAR c) -{ - return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); -} - -WINBOOL STDCALL IsCharAlphaW(WCHAR c) -{ - return (c >= L'A' && c <= L'Z') || (c >= L'a' && c <= L'z'); -} - - -WINBOOL STDCALL IsCharLowerA(CHAR c) -{ - return (c >= 'a' && c <= 'z'); -} - - -WINBOOL STDCALL IsCharLowerW(WCHAR c) -{ - return (c >= L'a' && c <= L'z'); -} - - -WINBOOL STDCALL IsCharUpperA(CHAR c) -{ - return (c >= 'A' && c <= 'Z' ); -} - - -WINBOOL STDCALL IsCharUpperW(WCHAR c) -{ - return (c >= L'A' && c <= L'Z' ); -} - - -DWORD STDCALL FormatMessageA( - DWORD dwFlags, - LPCVOID lpSource, - DWORD dwMessageId, - DWORD dwLanguageId, - LPSTR lpBuffer, - DWORD nSize, - va_list *Arguments -) { - LPSTR target,t; - DWORD talloced; - LPSTR from,f; - //DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; - DWORD nolinefeed = 0; - DWORD len; - - ////TRACE(resource, "(0x%lx,%p,%ld,0x%lx,%p,%ld,%p)\n", - // dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,Arguments); - //if (width) - // FIXME(resource,"line wrapping not supported.\n"); - from = NULL; - if (dwFlags & FORMAT_MESSAGE_FROM_STRING) { - len = lstrlenA((LPSTR)lpSource); - from = HeapAlloc( GetProcessHeap(),0, len+1 ); - CopyMemory(from,lpSource,len+1); - } - else if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { - len = 200; - from = HeapAlloc( GetProcessHeap(),0,200 ); - wsprintfA(from,"Systemmessage, messageid = 0x%08lx\n",dwMessageId); - } - else if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { - INT bufsize; - - dwMessageId &= 0xFFFF; - bufsize=LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,NULL,100); - if (bufsize) { - from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); - LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,from,bufsize+1); - } - } - target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100); - t = target; - talloced= 100; - -#define ADD_TO_T(c) \ - *t++=c;\ - if (t-target == talloced) {\ - target = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\ - t = target+talloced;\ - talloced*=2;\ - } - - if (from) { - f=from; - while (*f && !nolinefeed) { - if (*f=='%') { - int insertnr; - char *fmtstr,*sprintfbuf,*x,*lastf; - DWORD *argliststart; - - fmtstr = NULL; - lastf = f; - f++; - if (!*f) { - ADD_TO_T('%'); - continue; - } - switch (*f) { - case '1':case '2':case '3':case '4':case '5': - case '6':case '7':case '8':case '9': - insertnr=*f-'0'; - switch (f[1]) { - case '0':case '1':case '2':case '3': - case '4':case '5':case '6':case '7': - case '8':case '9': - f++; - insertnr=insertnr*10+*f-'0'; - f++; - break; - default: - f++; - break; - } - if (*f=='!') { - f++; - if (NULL!=(x=lstrchrA(f,'!'))) { - *x='\0'; - fmtstr=HeapAlloc(GetProcessHeap(),0,lstrlenA(f)+2); - wsprintfA(fmtstr,"%%%s",f); - f=x+1; - } else { - len = lstrlenA(f); - fmtstr=HeapAlloc(GetProcessHeap(),0,len + 1); - wsprintfA(fmtstr,"%%%s",f); - f+=lstrlenA(f); /*at \0*/ - } - } else - if(!Arguments) - break; - else { - fmtstr = HeapAlloc( GetProcessHeap(),0, 3 ); - fmtstr[0] = '%'; - fmtstr[1] = 's'; - fmtstr[2] = 0; - } - if (Arguments) { - if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) - argliststart=Arguments+insertnr-1; - else - argliststart=(*(DWORD**)Arguments)+insertnr-1; - - if (fmtstr[lstrlenA(fmtstr)-1]=='s') - sprintfbuf=HeapAlloc(GetProcessHeap(),0,lstrlenA((LPSTR)argliststart[0])+1); - else - sprintfbuf=HeapAlloc(GetProcessHeap(),0,100); - - /* CMF - This makes a BIG assumption about va_list */ - wvsprintfA(sprintfbuf, fmtstr, (va_list) argliststart); - x=sprintfbuf; - while (*x) { - ADD_TO_T(*x++); - } - HeapFree(GetProcessHeap(),0,sprintfbuf); - } else { - /* NULL Arguments - copy formatstr - * (probably wrong) - */ - while ((lastf - -WINBOOL -STDCALL -GetUserObjectInformationA( - HANDLE hObj, - int nIndex, - PVOID pvInfo, - DWORD nLength, - LPDWORD lpnLengthNeeded) -{ - return FALSE; -} - -WINBOOL -STDCALL -SetUserObjectInformationA( - HANDLE hObj, - int nIndex, - PVOID pvInfo, - DWORD nLength) -{ - return FALSE; -} - - - - -HKL -STDCALL -LoadKeyboardLayoutA( - LPCSTR pwszKLID, - UINT Flags) -{ - return 0; -} - -WINBOOL -STDCALL -GetKeyboardLayoutNameA( - LPSTR pwszKLID) -{ - return FALSE; -} - -HHOOK -STDCALL -SetWindowsHookA( - int nFilterType, - HOOKPROC lpfn) -{ - return 0; -} - - - -int -STDCALL -DrawTextExA(HDC HDC, LPSTR str, int i, LPRECT r, UINT u, LPDRAWTEXTPARAMS x) { return 0; } - -WINBOOL -STDCALL -GrayStringA( - HDC hDC, - HBRUSH hBrush, - GRAYSTRINGPROC lpOutputFunc, - LPARAM lpData, - int nCount, - int X, - int Y, - int nWidth, - int nHeight) { return 0; } - -WINBOOL -STDCALL -DrawStateA(HDC hDC, HBRUSH hBrush, DRAWSTATEPROC p, LPARAM lParam, WPARAM wParam, int i, int j, int k, int l, UINT u) { return 0; } - - - - - - - -HWND -STDCALL -FindWindowA( - LPCSTR lpClassName , - LPCSTR lpWindowName) { return 0; } - -HWND -STDCALL -FindWindowExA(HWND hWnd, HWND hWnd2, LPCSTR str, LPCSTR s) { return 0; } - - - - - -int -STDCALL -GetClipboardFormatNameA( - UINT format, - LPSTR lpszFormatName, - int cchMaxCount) { return 0; } - -WINBOOL -STDCALL -CharToOemA( - LPCSTR lpszSrc, - LPSTR lpszDst) { return 0; } - -WINBOOL -STDCALL -OemToCharA( - LPCSTR lpszSrc, - LPSTR lpszDst) { return 0; } - -WINBOOL -STDCALL -CharToOemBuffA( - LPCSTR lpszSrc, - LPSTR lpszDst, - DWORD cchDstLength) { return 0; } - -WINBOOL -STDCALL -OemToCharBuffA( - LPCSTR lpszSrc, - LPSTR lpszDst, - DWORD cchDstLength) { return 0; } - - - - -int -STDCALL -GetKeyNameTextA( - LONG lParam, - LPSTR lpString, - int nSize - ) { return 0; } - -SHORT -STDCALL -VkKeyScanA( - CHAR ch) { return 0; } - -SHORT -STDCALL VkKeyScanExA( - CHAR ch, - HKL dwhkl) { return 0; } - -UINT -STDCALL -MapVirtualKeyA( - UINT uCode, - UINT uMapType) { return 0; } - -UINT -STDCALL -MapVirtualKeyExA( - UINT uCode, - UINT uMapType, - HKL dwhkl) { return 0; } - -HACCEL -STDCALL -LoadAcceleratorsA( - HINSTANCE hInstance, - LPCSTR lpTableName) { return 0; } - -HACCEL -STDCALL -CreateAcceleratorTableA( - LPACCEL l, int i) { return 0; } - -int -STDCALL -CopyAcceleratorTableA( - HACCEL hAccelSrc, - LPACCEL lpAccelDst, - int cAccelEntries) { return 0; } - -int -STDCALL -TranslateAcceleratorA( - HWND hWnd, - HACCEL hAccTable, - LPMSG lpMsg) { return 0; } - - - - - -HCURSOR -STDCALL -LoadCursorFromFileA( - LPCSTR lpFileName) { return 0; } - - -HANDLE -STDCALL -LoadImageA( - HINSTANCE hInst, - LPCSTR str, - UINT u, - int i, - int j, - UINT k) { return 0; } - -int -STDCALL -DlgDirListA( - HWND hDlg, - LPSTR lpPathSpec, - int nIDListBox, - int nIDStaticPath, - UINT uFileType) { return 0; } - -WINBOOL -STDCALL -DlgDirSelectExA( - HWND hDlg, - LPSTR lpString, - int nCount, - int nIDListBox) { return 0; } - -int -STDCALL -DlgDirListComboBoxA( - HWND hDlg, - LPSTR lpPathSpec, - int nIDComboBox, - int nIDStaticPath, - UINT uFiletype) { return 0; } - -WINBOOL -STDCALL -DlgDirSelectComboBoxExA( - HWND hDlg, - LPSTR lpString, - int nCount, - int nIDComboBox) { return 0; } - -LRESULT -STDCALL -DefFrameProcA( - HWND hWnd, - HWND hWndMDIClient , - UINT uMsg, - WPARAM wParam, - LPARAM lParam) { return 0; } - -LRESULT -STDCALL -DefMDIChildProcA( - HWND hWnd, - UINT uMsg, - WPARAM wParam, - LPARAM lParam) { return 0; } - -HWND -STDCALL -CreateMDIWindowA( - LPSTR lpClassName, - LPSTR lpWindowName, - DWORD dwStyle, - int X, - int Y, - int nWidth, - int nHeight, - HWND hWndParent, - HINSTANCE hInstance, - LPARAM lParam - ) { return 0; } - -WINBOOL -STDCALL -WinHelpA( - HWND hWndMain, - LPCSTR lpszHelp, - UINT uCommand, - DWORD dwData - ) { return 0; } - -LONG -STDCALL -ChangeDisplaySettingsA( - LPDEVMODE lpDevMode, - DWORD dwFlags) { return 0; } - -WINBOOL -STDCALL -EnumDisplaySettingsA( - LPCSTR lpszDeviceName, - DWORD iModeNum, - LPDEVMODE lpDevMode) { return 0; } - - - - - -HSZ WINAPI -DdeCreateStringHandleA (DWORD dw, LPSTR str, int i) { return 0; } - -UINT WINAPI -DdeInitializeA (DWORD *dw, CALLB c, DWORD x, DWORD y) { return 0; } - -DWORD WINAPI -DdeQueryStringA (DWORD dw, HSZ h, LPSTR str, DWORD t, int i) { return 0; } diff --git a/reactos/lib/user32/misc/stubsw.c b/reactos/lib/user32/misc/stubsw.c deleted file mode 100644 index 946a637bc77..00000000000 --- a/reactos/lib/user32/misc/stubsw.c +++ /dev/null @@ -1,321 +0,0 @@ -#include - - - -WINBOOL -STDCALL -GetUserObjectInformationW( - HANDLE hObj, - int nIndex, - PVOID pvInfo, - DWORD nLength, - LPDWORD lpnLengthNeeded) -{ - return FALSE; -} - -WINBOOL -STDCALL -SetUserObjectInformationW( - HANDLE hObj, - int nIndex, - PVOID pvInfo, - DWORD nLength) -{ - return FALSE; -} - - - - - -HKL -STDCALL -LoadKeyboardLayoutW( - LPCWSTR pwszKLID, - UINT Flags) -{ - return 0; -} - -WINBOOL -STDCALL -GetKeyboardLayoutNameW( - LPWSTR pwszKLID) -{ - return FALSE; -} - - -HHOOK -STDCALL -SetWindowsHookW( - int nFilterType, - HOOKPROC lpfn) -{ - return 0; -} - - - - -int -STDCALL -DrawTextExW(HDC hDC, LPWSTR str, int i, LPRECT r, UINT u, LPDRAWTEXTPARAMS p) { return 0; } - -WINBOOL -STDCALL -GrayStringW( - HDC hDC, - HBRUSH hBrush, - GRAYSTRINGPROC lpOutputFunc, - LPARAM lpData, - int nCount, - int X, - int Y, - int nWidth, - int nHeight) { return 0; } - -WINBOOL STDCALL DrawStateW(HDC hDC, HBRUSH hBrush, DRAWSTATEPROC d, LPARAM lParam, WPARAM wParam, int i, int j, int k, int l, UINT u) { return 0; } - - - - -HWND -STDCALL -FindWindowW( - LPCWSTR lpClassName , - LPCWSTR lpWindowName) { return 0; } - -HWND -STDCALL -FindWindowExW(HWND hWnd, HWND hWnd2, LPCWSTR str, LPCWSTR s) { return 0; } - - - - - - -int -STDCALL -GetClipboardFormatNameW( - UINT format, - LPWSTR lpszFormatName, - int cchMaxCount) { return 0; } - -WINBOOL -STDCALL -CharToOemW( - LPCWSTR lpszSrc, - LPSTR lpszDst) { return 0; } - -WINBOOL -STDCALL -OemToCharW( - LPCSTR lpszSrc, - LPWSTR lpszDst) { return 0; } - -WINBOOL -STDCALL -CharToOemBuffW( - LPCWSTR lpszSrc, - LPSTR lpszDst, - DWORD cchDstLength) { return 0; } - -WINBOOL -STDCALL -OemToCharBuffW( - LPCSTR lpszSrc, - LPWSTR lpszDst, - DWORD cchDstLength) { return 0; } - - - -int -STDCALL -GetKeyNameTextW( - LONG lParam, - LPWSTR lpString, - int nSize - ) { return 0; } - -SHORT -STDCALL -VkKeyScanW( - WCHAR ch) { return 0; } - -SHORT -STDCALL VkKeyScanExW( - WCHAR ch, - HKL dwhkl) { return 0; } - -UINT -STDCALL -MapVirtualKeyW( - UINT uCode, - UINT uMapType) { return 0; } - -UINT -STDCALL -MapVirtualKeyExW( - UINT uCode, - UINT uMapType, - HKL dwhkl) { return 0; } - -HACCEL -STDCALL -LoadAcceleratorsW( - HINSTANCE hInstance, - LPCWSTR lpTableName) { return 0; } - -HACCEL -STDCALL -CreateAcceleratorTableW( - LPACCEL l, int i) { return 0; } - -int -STDCALL -CopyAcceleratorTableW( - HACCEL hAccelSrc, - LPACCEL lpAccelDst, - int cAccelEntries) { return 0; } - -int -STDCALL -TranslateAcceleratorW( - HWND hWnd, - HACCEL hAccTable, - LPMSG lpMsg) { return 0; } - - - - - - - - -HCURSOR -STDCALL -LoadCursorFromFileW( - LPCWSTR lpFileName) { return 0; } - - - -HANDLE -STDCALL -LoadImageW( - HINSTANCE hInst, - LPCWSTR str, - UINT u, - int i, - int j, - UINT k) { return 0; } - -int -STDCALL -LoadStringW( - HINSTANCE hInstance, - UINT uID, - LPWSTR lpBuffer, - int nBufferMax) { return 0; } - - -int -STDCALL -DlgDirListW( - HWND hDlg, - LPWSTR lpPathSpec, - int nIDListBox, - int nIDStaticPath, - UINT uFileType) { return 0; } - -WINBOOL -STDCALL -DlgDirSelectExW( - HWND hDlg, - LPWSTR lpString, - int nCount, - int nIDListBox) { return 0; } - -int -STDCALL -DlgDirListComboBoxW( - HWND hDlg, - LPWSTR lpPathSpec, - int nIDComboBox, - int nIDStaticPath, - UINT uFiletype) { return 0; } - -WINBOOL -STDCALL -DlgDirSelectComboBoxExW( - HWND hDlg, - LPWSTR lpString, - int nCount, - int nIDComboBox) { return 0; } - -LRESULT -STDCALL -DefFrameProcW( - HWND hWnd, - HWND hWndMDIClient , - UINT uMsg, - WPARAM wParam, - LPARAM lParam) { return 0; } - -LRESULT -STDCALL -DefMDIChildProcW( - HWND hWnd, - UINT uMsg, - WPARAM wParam, - LPARAM lParam) { return 0; } - -HWND -STDCALL -CreateMDIWindowW( - LPWSTR lpClassName, - LPWSTR lpWindowName, - DWORD dwStyle, - int X, - int Y, - int nWidth, - int nHeight, - HWND hWndParent, - HINSTANCE hInstance, - LPARAM lParam - ) { return 0; } - -WINBOOL -STDCALL -WinHelpW( - HWND hWndMain, - LPCWSTR lpszHelp, - UINT uCommand, - DWORD dwData - ) { return 0; } - -LONG -STDCALL -ChangeDisplaySettingsW( - LPDEVMODE lpDevMode, - DWORD dwFlags) { return 0; } - -WINBOOL -STDCALL -EnumDisplaySettingsW( - LPCWSTR lpszDeviceName, - DWORD iModeNum, - LPDEVMODE lpDevMode) { return 0; } - - - - -HSZ WINAPI -DdeCreateStringHandleW (DWORD dw, LPCWSTR str, int i) { return 0; } - -UINT WINAPI -DdeInitializeW (DWORD *dw, CALLB c, DWORD x, DWORD y) { return 0; } - -DWORD WINAPI -DdeQueryStringW (DWORD dw, HSZ h, LPCWSTR str, DWORD t, int i) { return 0; } \ No newline at end of file diff --git a/reactos/lib/user32/misc/sysmetr.c b/reactos/lib/user32/misc/sysmetr.c deleted file mode 100644 index 2568e520d14..00000000000 --- a/reactos/lib/user32/misc/sysmetr.c +++ /dev/null @@ -1,279 +0,0 @@ -/* - * System metrics functions - * - * Copyright 1994 Alexandre Julliard - * - */ - -#include -#include -#include - -#undef SM_CMETRICS -#define SM_CMETRICS (83) - -short sysMetrics[SM_CMETRICS+1] = { - - 800, // [SM_CXSCREEN] /* 0 */ - 600, // [SM_CYSCREEN] /* 1 */ - 19, // [SM_CXVSCROLL] /* 2 */ - 17, // [SM_CYHSCROLL] /* 3 */ - 19, // [SM_CYCAPTION] /* 4 */ - 1, // [SM_CXBORDER] /* 5 */ - 1, // [SM_CYBORDER] /* 6 */ - 3, // [SM_CXDLGFRAME] /* 7 */ - 3, // [SM_CYDLGFRAME] /* 8 */ - 17, // [SM_CYVTHUMB] /* 9 */ sysMetrics[SM_CXVSCROLL] - 1; - 17, // [SM_CXHTHUMB] /* 10 */ sysMetrics[SM_CXVSCROLL] - 1; - 32, // [SM_CXICON] /* 11 */ - 32, // [SM_CYICON] /* 12 */ - 32, // [SM_CXCURSOR] /* 13 */ - 32, // [SM_CYCURSOR] /* 14 */ - 19, // [SM_CYMENU] /* 15 */ - 800, // [SM_CXFULLSCREEN] /* 16 */ - 600, // [SM_CYFULLSCREEN] /* 17 */ - 0, // [SM_CYKANJIWINDOW] /* 18 */ - 0, // [SM_MOUSEPRESENT] /* 19 */ - 0, // [SM_CYVSCROLL] /* 20 */ - 0, // [SM_CXHSCROLL] /* 21 */ - 0, // [SM_DEBUG] /* 22 */ - 0, // [SM_SWAPBUTTON] /* 23 */ - 0, // [SM_RESERVED1] /* 24 */ - 0, // [SM_RESERVED2] /* 25 */ - 0, // [SM_RESERVED3] /* 26 */ - 0, // [SM_RESERVED4] /* 27 */ - 112, // [SM_CXMIN] /* 28 */ - 27, // [SM_CYMIN] /* 29 */ - 17, // [SM_CXSIZE] /* 30 */ - 17, // [SM_CYSIZE] /* 31 */ - 4, // [SM_CXFRAME] /* 32 */ - 4, // [SM_CYFRAME] /* 33 */ - 0, // [SM_CXMINTRACK] /* 34 */ - 0, // [SM_CYMINTRACK] /* 35 */ - 0, // [SM_CXDOUBLECLK] /* 36 */ - 0, // [SM_CYDOUBLECLK] /* 37 */ - 0, // [SM_CXICONSPACING] /* 38 */ - 0, // [SM_CYICONSPACING] /* 39 */ - 0, // [SM_MENUDROPALIGNMENT] /* 40 */ - 0, // [SM_PENWINDOWS] /* 41 */ - 0, // [SM_DBCSENABLED] /* 42 */ - 0, // [SM_CMOUSEBUTTONS] /* 43 */ - // [SM_CXDLGFRAME] /* win40 name change */ - // [SM_CYDLGFRAME] /* win40 name change */ - // [SM_CXFRAME] /* win40 name change */ - // [SM_CYFRAME] /* win40 name change */ - 0, // [SM_SECURE] /* 44 */ - 2, // [SM_CXEDGE] /* 45 */ // sysMetrics[SM_CXBORDER] + 1; - 2, // [SM_CYEDGE] /* 46 */ - 0, // [SM_CXMINSPACING] /* 47 */ - 0, // [SM_CYMINSPACING] /* 48 */ - 14, // [SM_CXSMICON] /* 49 */ - 14, // [SM_CYSMICON] /* 50 */ - 0, // [SM_CYSMCAPTION] /* 51 */ - 0, // [SM_CXSMSIZE] /* 52 */ - 0, // [SM_CYSMSIZE] /* 53 */ - 19, // [SM_CXMENUSIZE] /* 54 */ - 19, // [SM_CYMENUSIZE] /* 55 */ - 8, // [SM_ARRANGE] /* 56 */ - 160, // [SM_CXMINIMIZED] /* 57 */ - 24, // [SM_CYMINIMIZED] /* 58 */ - 0, // [SM_CXMAXTRACK] /* 59 */ - 0, // [SM_CYMAXTRACK] /* 60 */ - 0, // [SM_CXMAXIMIZED] /* 61 */ - 0, // [SM_CYMAXIMIZED] /* 62 */ - 3, // [SM_NETWORK] /* 63 */ - 0, // [SM_CLEANBOOT] /* 67 */ - 2, // [SM_CXDRAG] /* 68 */ - 2, // [SM_CYDRAG] /* 69 */ - 0, // [SM_SHOWSOUNDS] /* 70 */ - 2, // [SM_CXMENUCHECK] /* 71 */ - 2, // [SM_CYMENUCHECK] /* 72 */ - 0, // [SM_SLOWMACHINE] /* 73 */ - 0, // [SM_MIDEASTENABLED] /* 74 */ - 0, // [SM_MOUSEWHEELPRESENT] /* 75 */ - 800, // [SM_CXVIRTUALSCREEN] /* 76 */ - 600, // [SM_CYVIRTUALSCREEN] /* 77 */ - 0, // [SM_YVIRTUALSCREEN] /* 78 */ - 0, // [SM_XVIRTUALSCREEN] /* 79 */ - 1, // [SM_CMONITORS] /* 81 */ - 1 // [SM_SAMEDISPLAYFORMAT] /* 82 */ - - }; - - - -int STDCALL GetSystemMetrics(int nIndex) -{ - if ( nIndex >= 0 && nIndex <= SM_CMETRICS+1 ) - return sysMetrics[nIndex]; - return 0; -} - - -WINBOOL STDCALL SystemParametersInfoA(UINT uiAction, - UINT uiParam, PVOID pvParam, UINT fWinIni ) -{ - return FALSE; -} - -WINBOOL STDCALL SystemParametersInfoW(UINT uiAction, - UINT uiParam, PVOID pvParam, UINT fWinIni ) -{ - return FALSE; -} -#if 0 - /*********************************************************************** - * SYSMETRICS_Init - * - * Initialisation of the system metrics array. - * - * Differences in return values between 3.1 and 95 apps under Win95 (FIXME ?): - * SM_CXVSCROLL x+1 x - * SM_CYHSCROLL x+1 x - * SM_CXDLGFRAME x-1 x - * SM_CYDLGFRAME x-1 x - * SM_CYCAPTION x+1 x - * SM_CYMENU x-1 x - * SM_CYFULLSCREEN x-1 x - * - * (collides with TWEAK_WineLook sometimes, - * so changing anything might be difficult) - */ - - - - void SYSMETRICS_Init(void) - { - sysMetrics[SM_CXCURSOR] = 32; - sysMetrics[SM_CYCURSOR] = 32; - sysMetrics[SM_CXSCREEN] = screenWidth; - sysMetrics[SM_CYSCREEN] = screenHeight; - sysMetrics[SM_CXVSCROLL] = - PROFILE_GetWineIniInt("Tweak.Layout", "ScrollBarWidth", 16) + 1; - sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL]; - if (TWEAK_WineLook > WIN31_LOOK) - sysMetrics[SM_CYCAPTION] = - PROFILE_GetWineIniInt("Tweak.Layout", "CaptionHeight", 19); - else - sysMetrics[SM_CYCAPTION] = 2 + - PROFILE_GetWineIniInt("Tweak.Layout", "CaptionHeight", 18); - sysMetrics[SM_CXBORDER] = 1; - sysMetrics[SM_CYBORDER] = sysMetrics[SM_CXBORDER]; - sysMetrics[SM_CXDLGFRAME] = - PROFILE_GetWineIniInt("Tweak.Layout", "DialogFrameWidth", - (TWEAK_WineLook > WIN31_LOOK) ? 3 : 4); - sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME]; - */ sysMetrics[SM_CYVTHUMB] = sysMetrics[SM_CXVSCROLL] - 1; - */ sysMetrics[SM_CXHTHUMB] = sysMetrics[SM_CYVTHUMB]; - */ sysMetrics[SM_CXICON] = 32; - */ sysMetrics[SM_CYICON] = 32; - if (TWEAK_WineLook > WIN31_LOOK) - sysMetrics[SM_CYMENU] = - PROFILE_GetWineIniInt("Tweak.Layout", "MenuHeight", 19); - else - sysMetrics[SM_CYMENU] = - PROFILE_GetWineIniInt("Tweak.Layout", "MenuHeight", 18); - sysMetrics[SM_CXFULLSCREEN] = sysMetrics[SM_CXSCREEN]; - sysMetrics[SM_CYFULLSCREEN] = - sysMetrics[SM_CYSCREEN] - sysMetrics[SM_CYCAPTION]; - sysMetrics[SM_CYKANJIWINDOW] = 0; - sysMetrics[SM_MOUSEPRESENT] = 1; - sysMetrics[SM_CYVSCROLL] = sysMetrics[SM_CYVTHUMB]; - sysMetrics[SM_CXHSCROLL] = sysMetrics[SM_CXHTHUMB]; - sysMetrics[SM_DEBUG] = 0; - - /* FIXME: The following should look for the registry key to see if the - buttons should be swapped. */ - sysMetrics[SM_SWAPBUTTON] = 0; - - sysMetrics[SM_RESERVED1] = 0; - sysMetrics[SM_RESERVED2] = 0; - sysMetrics[SM_RESERVED3] = 0; - sysMetrics[SM_RESERVED4] = 0; - - /* FIXME: The following two are calculated, but how? */ - sysMetrics[SM_CXMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 112 : 100; - sysMetrics[SM_CYMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 27 : 28; - - sysMetrics[SM_CXSIZE] = sysMetrics[SM_CYCAPTION] - 2; - sysMetrics[SM_CYSIZE] = sysMetrics[SM_CXSIZE]; - sysMetrics[SM_CXFRAME] = GetProfileInt32A("Windows", "BorderWidth", 4); - sysMetrics[SM_CYFRAME] = sysMetrics[SM_CXFRAME]; - sysMetrics[SM_CXMINTRACK] = sysMetrics[SM_CXMIN]; - sysMetrics[SM_CYMINTRACK] = sysMetrics[SM_CYMIN]; - sysMetrics[SM_CXDOUBLECLK] = -(GetProfileInt32A("Windows", "DoubleClickWidth", 4) + 1) & ~1; - sysMetrics[SM_CYDOUBLECLK] = -(GetProfileInt32A("Windows","DoubleClickHeight", 4) + 1) & ~1; - sysMetrics[SM_CXICONSPACING] = - GetProfileInt32A("Desktop","IconSpacing", 75); - sysMetrics[SM_CYICONSPACING] = - GetProfileInt32A("Desktop", "IconVerticalSpacing", 75); - sysMetrics[SM_MENUDROPALIGNMENT] = - GetProfileInt32A("Windows", "MenuDropAlignment", 0); - sysMetrics[SM_PENWINDOWS] = 0; - sysMetrics[SM_DBCSENABLED] = 0; - - /* FIXME: Need to query X for the following */ - sysMetrics[SM_CMOUSEBUTTONS] = 3; - - sysMetrics[SM_SECURE] = 0; - sysMetrics[SM_CXEDGE] = sysMetrics[SM_CXBORDER] + 1; - sysMetrics[SM_CYEDGE] = sysMetrics[SM_CXEDGE]; - sysMetrics[SM_CXMINSPACING] = 160; - sysMetrics[SM_CYMINSPACING] = 24; - sysMetrics[SM_CXSMICON] = - sysMetrics[SM_CYSIZE] - (sysMetrics[SM_CYSIZE] % 2) - 2; - sysMetrics[SM_CYSMICON] = sysMetrics[SM_CXSMICON]; - sysMetrics[SM_CYSMCAPTION] = 16; - sysMetrics[SM_CXSMSIZE] = 15; - sysMetrics[SM_CYSMSIZE] = sysMetrics[SM_CXSMSIZE]; - sysMetrics[SM_CXMENUSIZE] = sysMetrics[SM_CYMENU]; - sysMetrics[SM_CYMENUSIZE] = sysMetrics[SM_CXMENUSIZE]; - - /* FIXME: What do these mean? */ - sysMetrics[SM_ARRANGE] = 8; - sysMetrics[SM_CXMINIMIZED] = 160; - sysMetrics[SM_CYMINIMIZED] = 24; - - /* FIXME: How do I calculate these? */ - sysMetrics[SM_CXMAXTRACK] = - sysMetrics[SM_CXSCREEN] + 4 + 2 * sysMetrics[SM_CXFRAME]; - sysMetrics[SM_CYMAXTRACK] = - sysMetrics[SM_CYSCREEN] + 4 + 2 * sysMetrics[SM_CYFRAME]; - sysMetrics[SM_CXMAXIMIZED] = - sysMetrics[SM_CXSCREEN] + 2 * sysMetrics[SM_CXFRAME]; - sysMetrics[SM_CYMAXIMIZED] = - sysMetrics[SM_CYSCREEN] - 45; - sysMetrics[SM_NETWORK] = 3; - - /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */ - sysMetrics[SM_CLEANBOOT] = 0; - - sysMetrics[SM_CXDRAG] = 2; - sysMetrics[SM_CYDRAG] = 2; - sysMetrics[SM_SHOWSOUNDS] = 0; - sysMetrics[SM_CXMENUCHECK] = 2; - sysMetrics[SM_CYMENUCHECK] = 2; - - /* FIXME: Should check the type of processor for the following */ - sysMetrics[SM_SLOWMACHINE] = 0; - - /* FIXME: Should perform a check */ - sysMetrics[SM_MIDEASTENABLED] = 0; - - sysMetrics[SM_MOUSEWHEELPRESENT] = 0; - - sysMetrics[SM_CXVIRTUALSCREEN] = sysMetrics[SM_CXSCREEN]; - sysMetrics[SM_CYVIRTUALSCREEN] = sysMetrics[SM_CYSCREEN]; - sysMetrics[SM_XVIRTUALSCREEN] = 0; - sysMetrics[SM_YVIRTUALSCREEN] = 0; - sysMetrics[SM_CMONITORS] = 1; - sysMetrics[SM_SAMEDISPLAYFORMAT] = 1; - sysMetrics[SM_CMETRICS] = SM_CMETRICS; -} - - - -#endif - diff --git a/reactos/lib/user32/misc/vk.c b/reactos/lib/user32/misc/vk.c deleted file mode 100644 index 008912d98a4..00000000000 --- a/reactos/lib/user32/misc/vk.c +++ /dev/null @@ -1,77 +0,0 @@ -#include - -SHORT -STDCALL -GetKeyState( int nVirtKey ) -{ - return 0; -} - -UINT -STDCALL -GetKBCodePage( - VOID) -{ - return 0; -} - -SHORT -STDCALL -GetAsyncKeyState( - int vKey) -{ - return 0; -} - - -WINBOOL -STDCALL -GetKeyboardState( - PBYTE lpKeyState) -{ - return FALSE; -} - - -WINBOOL -STDCALL -SetKeyboardState( - LPBYTE lpKeyState) -{ - return FALSE; -} - - -int -STDCALL -GetKeyboardType( - int nTypeFlag) -{ - return 0; -} - - -int -STDCALL -ToAscii( - UINT uVirtKey, - UINT uScanCode, - PBYTE lpKeyState, - LPWORD lpChar, - UINT uFlags) -{ - return ToAsciiEx(uVirtKey,uScanCode, lpKeyState, lpChar, uFlags, NULL); -} - - -int -STDCALL -ToAsciiEx( - UINT uVirtKey, - UINT uScanCode, - PBYTE lpKeyState, - LPWORD lpChar, - UINT uFlags, - HKL dwhkl) -{ -} \ No newline at end of file diff --git a/reactos/lib/user32/misc/winstat.c b/reactos/lib/user32/misc/winstat.c deleted file mode 100644 index bb6296a8ab1..00000000000 --- a/reactos/lib/user32/misc/winstat.c +++ /dev/null @@ -1,240 +0,0 @@ -#include - - -HWINSTA WinStation = NULL; -HDESK Desktop = NULL; - -HWINSTA -STDCALL -CreateWindowStationA( - LPSTR lpwinsta, - DWORD dwReserved, - DWORD dwDesiredAccess, - LPSECURITY_ATTRIBUTES lpsa - -) -{ - return CreateFileA("\\\\.\\WinStat", - dwDesiredAccess, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL); -} - -HWINSTA -STDCALL -CreateWindowStationW( - LPWSTR lpwinsta, - DWORD dwReserved, - DWORD dwDesiredAccess, - LPSECURITY_ATTRIBUTES lpsa - -) -{ - return CreateFileW(L"\\\\.\\WinStat", - dwDesiredAccess, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL); -} - - -#undef CreateDesktop -HDESK -STDCALL -CreateDesktopA( - LPSTR lpszDesktop, - LPSTR lpszDevice, - LPDEVMODE pDevmode, - DWORD dwFlags, - DWORD dwDesiredAccess, - LPSECURITY_ATTRIBUTES lpsa) - -{ - -} - -HDESK -STDCALL -CreateDesktopW( - LPWSTR lpszDesktop, - LPWSTR lpszDevice, - LPDEVMODE pDevmode, - DWORD dwFlags, - DWORD dwDesiredAccess, - LPSECURITY_ATTRIBUTES lpsa) - -{ - -} - - -HDESK -STDCALL -OpenInputDesktop( - DWORD dwFlags, - WINBOOL fInherit, - DWORD dwDesiredAccess) -{ - return 0; -} - -WINBOOL -STDCALL -EnumDesktopWindows( - HDESK hDesktop, - ENUMWINDOWSPROC lpfn, - LPARAM lParam) -{ - return FALSE; -} - - -WINBOOL -STDCALL -SwitchDesktop( - HDESK hDesktop) -{ - return FALSE; -} - - -WINBOOL -STDCALL -SetThreadDesktop( - HDESK hDesktop) -{ - return FALSE; -} - - - -HDESK -STDCALL -OpenDesktopA( - LPSTR lpszDesktop, - DWORD dwFlags, - WINBOOL fInherit, - DWORD dwDesiredAccess) -{ - return Desktop; -} - -HDESK -STDCALL -OpenDesktopW( - LPWSTR lpszDesktop, - DWORD dwFlags, - WINBOOL fInherit, - DWORD dwDesiredAccess) -{ - return Desktop; -} - -WINBOOL -STDCALL -CloseDesktop( - HDESK hDesktop) -{ - return 0; -} - - -HDESK -STDCALL -GetThreadDesktop( - DWORD dwThreadId) -{ - return 0; -} - - -WINBOOL -STDCALL -CloseWindowStation( - HWINSTA hWinSta) -{ - return 0; -} - - -WINBOOL -STDCALL -SetProcessWindowStation( - HWINSTA hWinSta) -{ - return FALSE; -} - - -HWINSTA -STDCALL -GetProcessWindowStation( - VOID) -{ - return WinStation; -} - - - -WINBOOL -STDCALL -EnumDesktopsA( - HWINSTA hwinsta, - DESKTOPENUMPROC lpEnumFunc, - LPARAM lParam) { return FALSE; } - -WINBOOL -STDCALL -EnumDesktopsW( - HWINSTA hwinsta, - DESKTOPENUMPROC lpEnumFunc, - LPARAM lParam) { return FALSE; } - - - -WINBOOL -WINAPI -EnumWindowStationsA( - ENUMWINDOWSTATIONPROC lpEnumFunc, - LPARAM lParam) -{ - return FALSE; -} - -BOOL -WINAPI -EnumWindowStationsW( - ENUMWINDOWSTATIONPROC lpEnumFunc, - LPARAM lParam) -{ - return FALSE; -} - -HWINSTA -STDCALL -OpenWindowStationA( - LPSTR lpszWinSta, - WINBOOL fInherit, - DWORD dwDesiredAccess) -{ - return WinStation; -} - - -HWINSTA -STDCALL -OpenWindowStationW( - LPWSTR lpszWinSta, - WINBOOL fInherit, - DWORD dwDesiredAccess) -{ - return WinStation; -} - - -HDESK STDCALL GetInputDesktop(VOID) { return Desktop; } \ No newline at end of file diff --git a/reactos/lib/user32/resources/sysres.c b/reactos/lib/user32/resources/sysres.c deleted file mode 100644 index 2fbadf1a384..00000000000 --- a/reactos/lib/user32/resources/sysres.c +++ /dev/null @@ -1,72 +0,0 @@ - -#include -#include -#include - -/*********************************************************************** - * SYSRES_GetResourcePtr - * - * Return a pointer to a system resource. - */ -LPCVOID SYSRES_GetResPtr( int id ) -{ -// return SYSRES_Resources[Options.language][id]->data; - - - return NULL; -} - -int -STDCALL -LoadStringA( HINSTANCE hInstance, - UINT uID, - LPSTR lpBuffer, - int nBufferMax) -{ - HRSRC rsc; - PBYTE ptr; - int len; - int count, dest = uID % 16; - PWSTR pwstr; - UNICODE_STRING UString; - ANSI_STRING AString; - NTSTATUS Status; - - rsc = FindResource( (HMODULE)hInstance, - MAKEINTRESOURCE( (uID / 16) + 1 ), - RT_STRING ); - if( rsc == NULL ) - return 0; - // get pointer to string table - ptr = (PBYTE)LoadResource( (HMODULE)hInstance, rsc ); - if( ptr == NULL ) - return 0; - for( count = 0; count <= dest; count++ ) - { - // walk each of the 16 string slots in the string table - len = (*(USHORT *)ptr) * 2; // length is in unicode chars, convert to bytes - ptr += 2; // first 2 bytes are length, string follows - pwstr = (PWSTR)ptr; - ptr += len; - } - if( !len ) - return 0; // zero means no string is there - // convert unitocde to ansi, and copy string to caller buffer - UString.Length = UString.MaximumLength = len; - UString.Buffer = pwstr; - memset( &AString, 0, sizeof AString ); - Status = RtlUnicodeStringToAnsiString( &AString, &UString, TRUE ); - if( !NT_SUCCESS( Status ) ) - { - SetLastErrorByStatus( Status ); - return 0; - } - nBufferMax--; // save room for the null - if( nBufferMax > AString.Length ) - nBufferMax = AString.Length; - memcpy( lpBuffer, AString.Buffer, nBufferMax ); - lpBuffer[nBufferMax] = 0; - RtlFreeAnsiString( &AString ); - return nBufferMax; -} -