Release 940201

Tue Feb  1 21:14:47 1994  Bob Amstadt  (bob@pooh)

	* [loader/selector.c]
	Added function CreateNewSegments().  Modified IPCCopySelector
	to allow aliasing to any arbitrary memory space.

	* [memory/global.c]
	Fixed potential bug in GlobalGetFreeSegments().

	* [memory/linear.c]
	Created functions GlobalLinearLock() and GlobalLinearUnlock().

Tue Feb  1 05:51:43 1994  julliard@di.epfl.ch (Alexandre Julliard)

	* [controls/widgets.c]
	Removed CAPTION window class.

	* [loader/cursor.c]
	Bug fix in LoadCursor(): don't allocate memory every time for
	built-in cursors.

	* [windows/clipping.c]
	Invalidate child windows in InvalidateRgn().

	* [windows/defwnd.c]
	Added repaint of the caption when changing window text.

	* [windows/event.c]
	Modified SetCapture() to allow keyboard events while capturing.

	* [windows/message.c]
	New function MSG_GetHardwareMessage(), to do mouse tracking
	without returning control to the Windows program.

	* [windows/nonclient.c]
	A couple of changes in frame drawing for DLGMODALFRAME windows.
	Rewritten window moving code, to use MSG_GetHardwareMessage()
	instead of non-client mouse events (this is the way Windows
	does it), and to send WM_ENTERSIZEMOVE messages.
	Removed WM_NCBUTTONUP and WM_NCMOUSEMOVE handlers.

	* [windows/win.c]
	Allocate temporary structures on the USER heap instead of
	using GlobalAlloc().

	* [windows/winpos.c]
	Added function WINPOS_GetMinMaxInfo() to get sizing informations.

Jan 31, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [windows/nonclient.c]
	Call to StdDrawScrollBar() during NC's drawing.
	Call to NC_ScrollBarButtonDown() on NC mouse events WM_LBUTTONDOWN.
	Call to NC_ScrollBarButtonUp() on NC mouse events WM_LBUTTONUP.
	Call to NC_ScrollBarMouseMove() on NC mouse events WM_MOUSEMOVE.

	* [controls/menu.c]
	New GetSubMenu() function.
	Move GetMenu() & SetMenu() functions from 'windows/win.c'.

	* [controls/listbox.c]
	Start changes to satisfy recent changes in scrollbars/windows.

	* [loader/resource.c]
	Put some code in LoadAccelerators() stub.
	New TranslateAccelerator() function.

	* [windows/win.c]
	Remove GetMenu() & SetMenu() functions.
	Call to NC_CreateScrollBars() if required by CreateWindow().

Mon Jan 24 10:40:10 EST 1994 John Richardson (jrichard@cs.uml.edu)

        * [window/win.c]
        Added functions EnumWindows, EnumChildWindows, and helper
        WIN_EnumChildWin.  EnumWindows won't list all wine windows
        because GetDesktopWindow isn't complete.  However, the code
        is in place for it to work correctly and only needs 
        GetDesktopWindow to do so.  

Tue Jan 25 05:51:47 1994  julliard@di.epfl.ch (Alexandre Julliard)

	* [windows/defwnd.c]
	Added handling of activation messages (WM_ACTIVATE,
	WM_NCACTIVATE, WM_MOUSEACTIVATE)

	* [windows/event.c]
	De-activate the window when losing input focus.

	* [windows/focus.c]
	Bug fix in SetFocus().

	* [windows/message.c]
	Added activation of the window on mouse-clicks.

	* [windows/nonclient.c]
	Changed non-client area painting to use the correct colors
	depending upon the activation state.
	Added WM_NCACTIVATE message handling.
	Fixed a couple of bugs in window moving and resizing.

	* [windows/winpos.c]
	Implemented Get/SetActiveWindow().
	Implemented SWP_NOACTIVATE flag in SetWindowPos().

Jan 17, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [misc/message.c]
	MessageBox has a CaptionBar for his title except for
		MB_SYSTEMMODAL with MB_ICONHAND.

	* [windows/nonclient.c]
	Call to NC_TrackSysMenu on SysMenu button mouse click.

	* [windows/defwnd.c]
	Call to NC_TrackSysMenu on Alt key (VK_MENU).

	* [controls/menu.c]
	New GetSystemMenu() function.
	New CopySystemMenu() internal function.
	New NC_TrackSysMenu() internal function.

	* [include/windows.h]
	New WM_INITMENU, WM_INITMENUPOPUP, WM_MENUSELECT & WM_MENUCHAR defines.
diff --git a/controls/menu.c b/controls/menu.c
index 8c43e6f..add8f18 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -4,18 +4,26 @@
 
 /*
 #define DEBUG_MENU
+#define DEBUG_SYSMENU
 */
 #define USE_POPUPMENU
 
 #include <X11/Intrinsic.h>
 #include <X11/StringDefs.h>
 #include "windows.h"
+#include "sysmetrics.h"
 #include "menu.h"
 #include "heap.h"
 #include "win.h"
 #include "bitmaps/check_bitmap"
 #include "bitmaps/nocheck_bitmap"
 
+#define SC_ABOUTWINE     SC_SCREENSAVE+1
+#define SC_SYSMENU	 SC_SCREENSAVE+2
+#define SC_ABOUTWINEDLG	 SC_SCREENSAVE+3
+
+extern HINSTANCE hSysRes;
+HMENU	hSysMenu = 0;
 HBITMAP hStdCheck = 0;
 HBITMAP hStdMnArrow = 0;
 
@@ -40,9 +48,12 @@
 LPSTR GetShortCutString(LPSTR str);
 WORD GetShortCutPos(LPSTR str);
 BOOL HideAllSubPopupMenu(LPPOPUPMENU menu);
+HMENU CopySysMenu();
 WORD * ParseMenuResource(WORD *first_item, int level, HMENU hMenu);
 void SetMenuLogicalParent(HMENU hMenu, HWND hWnd);
 
+BOOL FAR PASCAL AboutWine_Proc(HWND hDlg, WORD msg, WORD wParam, LONG lParam);
+
 /***********************************************************************
  *           PopupMenuWndProc
  */
@@ -98,13 +109,26 @@
 	return 0;
     case WM_COMMAND:
 	lppop = PopupMenuGetWindowAndStorage(hwnd, &wndPtr);
-#ifdef DEBUG_MENU
-    	printf("PopupMenu // push to lower parent WM_COMMAND !\n");
-#endif
-	if (lppop->hWndParent != (HWND)NULL)
+	if (lppop->hWndParent != (HWND)NULL) {
 	    SendMessage(lppop->hWndParent, WM_COMMAND, wParam, lParam);
-	else 
-	    SendMessage(lppop->ownerWnd, WM_COMMAND, wParam, lParam);
+#ifdef DEBUG_MENU
+	    printf("PopupMenu // push to lower parent WM_COMMAND !\n");
+#endif
+	    }
+	else {
+	    if (lppop->SysFlag == 0) {
+		SendMessage(lppop->ownerWnd, WM_COMMAND, wParam, lParam);
+#ifdef DEBUG_MENU
+		printf("PopupMenu // push to Owner WM_COMMAND !\n");
+#endif
+		}
+	    else {
+#ifdef DEBUG_SYSMENU
+		printf("PopupMenu // push to Owner WM_SYSCOMMAND !\n");
+#endif
+		SendMessage(lppop->ownerWnd, WM_SYSCOMMAND, wParam, lParam);
+		}
+	    }
 	if (lppop->BarFlags == 0) ShowWindow(hwnd, SW_HIDE);
     	break;
     case WM_SHOWWINDOW:
@@ -169,16 +193,18 @@
 		GetClientRect(hwnd, &rect);
 		if (lppop->BarFlags != 0) {
 		    y = rect.bottom - rect.top;
+		    GetWindowRect(hwnd, &rect);
+		    y += rect.top;
 		    TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON, 
-			lpitem->rect.left, 0, 
-			0, lppop->ownerWnd, (LPRECT)NULL);
+			rect.left + lpitem->rect.left, 
+			y, 0, lppop->ownerWnd, (LPRECT)NULL);
 		    }
 		else {
 		    x = rect.right;
 		    GetWindowRect(hwnd, &rect);
 		    x += rect.left;
 		    TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON, 
-			x, lpitem->rect.top,
+			x, rect.top + lpitem->rect.top,
 			0, lppop->ownerWnd, (LPRECT)NULL);
 		    }
 		break;
@@ -199,12 +225,40 @@
 	    if (((lpitem->item_flags & MF_SEPARATOR) != MF_SEPARATOR) &&
 		((lpitem->item_flags & MF_POPUP) != MF_POPUP)) {
 	    	ShowWindow(lppop->hWnd, SW_HIDE);
-		if (lppop->hWndParent != (HWND)NULL)
+		if (lppop->hWndParent != (HWND)NULL) {
 		    SendMessage(lppop->hWndParent, WM_COMMAND, 
 					lpitem->item_id, 0L);
-		else 
-		    SendMessage(lppop->ownerWnd, WM_COMMAND, 
+#ifdef DEBUG_MENU
+		    printf("PopupMenu // WM_COMMAND to ParentMenu wParam=%d !\n", 
+			lpitem->item_id);
+#endif
+		    }
+		else {
+		    if (lppop->SysFlag == 0) {
+#ifdef DEBUG_MENU
+			printf("PopupMenu // WM_COMMAND wParam=%d !\n", 
+				lpitem->item_id);
+#endif
+			SendMessage(lppop->ownerWnd, WM_COMMAND, 
 					lpitem->item_id, 0L);
+			}
+		    else {
+			if (lpitem->item_id == SC_ABOUTWINE) {
+			    printf("SysMenu // Show 'About Wine ...' !\n");
+/*			    DialogBox(hSysRes, MAKEINTRESOURCE(SC_ABOUTWINEDLG), */
+			    DialogBox(hSysRes, MAKEINTRESOURCE(2), 
+				GetParent(hwnd), (FARPROC)AboutWine_Proc);
+			    }
+			else {
+			    SendMessage(lppop->ownerWnd, WM_SYSCOMMAND,
+						 lpitem->item_id, 0L);
+#ifdef DEBUG_SYSMENU
+			    printf("PopupMenu // WM_SYSCOMMAND wParam=%04X !\n", 
+					lpitem->item_id);
+#endif
+			    }
+			}
+		    }
 #ifdef DEBUG_MENU
 		printf("PopupMenu // SendMessage WM_COMMAND wParam=%d !\n", 
 			lpitem->item_id);
@@ -248,10 +302,9 @@
 		    if (lppop2 == NULL) break;
 		    if (lppop->BarFlags != 0) {
 			lppop2->hWndParent = hwnd;
-			GetClientRect(hwnd, &rect);
-			y = rect.bottom - rect.top;
+			GetWindowRect(hwnd, &rect);
 			TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON, 
-				lpitem->rect.left, 0, 
+				lpitem->rect.left, rect.top, 
 				0, lppop->ownerWnd, (LPRECT)NULL);
 			}
 		    }
@@ -747,6 +800,9 @@
     HFONT	hOldFont;
     UINT  	i, OldWidth, TempWidth;
     DWORD	dwRet;
+#ifdef DEBUG_MENUCALC
+	printf("PopupMenuCalcSize hWnd=%04X !\n", hWnd);
+#endif
     lppop = PopupMenuGetWindowAndStorage(hwnd, &wndPtr);
     if (lppop == NULL) return;
     if (lppop->nItems == 0) return;
@@ -759,6 +815,9 @@
     lpitem = lppop->firstItem;
     for(i = 0; i < lppop->nItems; i++) {
 	if (lpitem == NULL) break;
+#ifdef DEBUG_MENUCALC
+	printf("PopupMenuCalcSize item #%d !\n", i);
+#endif
 	rect.right = rect.left + lppop->Width;
 	if ((lpitem->item_flags & MF_SEPARATOR) == MF_SEPARATOR) {
 	    rect.bottom = rect.top + 3;
@@ -788,11 +847,10 @@
     if (OldWidth < lppop->Width) goto CalcAGAIN;
     lppop->Height = rect.bottom;
 #ifdef DEBUG_MENUCALC
-    printf("PopupMenuCalcSize w=%d h=%d !\n", 
-    	lppop->Width, lppop->Height);
+    printf("PopupMenuCalcSize w=%d h=%d !\n", lppop->Width, lppop->Height);
 #endif
     SelectObject(hDC, hOldFont);
-    ReleaseDC(0, hDC);
+    ReleaseDC(hwnd, hDC);
 }
 
 
@@ -1775,6 +1833,7 @@
     menu->hWndParent	  = 0;
     menu->MouseFlags	  = 0;
     menu->BarFlags	  = 0;
+    menu->SysFlag	  = FALSE;
     menu->Width = 100;
     menu->Height = 0;
     return hMenu;
@@ -1798,8 +1857,8 @@
     wndPtr = WIN_FindWndPtr(hWnd);
     lppop->ownerWnd = hWnd;
     if (lppop->hWnd == (HWND)NULL) {
-        lppop->hWnd = CreateWindow("POPUPMENU", "", WS_CHILD | WS_VISIBLE,
-        	x, y, lppop->Width, lppop->Height, hWnd, 0, 
+        lppop->hWnd = CreateWindow("POPUPMENU", "", WS_POPUP | WS_VISIBLE,
+        	x, y, lppop->Width, lppop->Height, (HWND)NULL, 0, 
         	wndPtr->hInstance, (LPSTR)lppop);
         }
     else {
@@ -1828,6 +1887,43 @@
 
 
 /**********************************************************************
+ *			NC_TrackSysMenu		[Internal]
+ */
+void NC_TrackSysMenu(hWnd)
+{
+    RECT	rect;
+    LPPOPUPMENU	lpsys;
+    WND *wndPtr = WIN_FindWndPtr(hWnd);    
+#ifdef DEBUG_MENU
+    printf("NC_TrackSysMenu hWnd=%04X !\n", hWnd);
+#endif
+    if (!wndPtr) return;
+    lpsys = (LPPOPUPMENU)GlobalLock(wndPtr->hSysMenu);
+#ifdef DEBUG_MENU
+    printf("NC_TrackSysMenu wndPtr->hSysMenu=%04X !\n", wndPtr->hSysMenu);
+#endif
+    if (lpsys == NULL) return;
+#ifdef DEBUG_MENU
+    printf("NC_TrackSysMenu wndPtr->hSysMenu=%04X !\n", wndPtr->hSysMenu);
+#endif
+    lpsys->BarFlags = FALSE;
+    lpsys->SysFlag = TRUE;
+    if (!IsWindowVisible(lpsys->hWnd)) {
+	GetWindowRect(hWnd, &rect);
+#ifdef DEBUG_MENU
+	printf("NC_TrackSysMenu lpsys->hWnd=%04X !\n", lpsys->hWnd);
+#endif
+	TrackPopupMenu(wndPtr->hSysMenu, TPM_LEFTBUTTON, 
+		rect.left, rect.top + SYSMETRICS_CYSIZE, 
+		0, hWnd, (LPRECT)NULL);
+	}
+    else {
+	ShowWindow(lpsys->hWnd, SW_HIDE);
+	}
+}
+
+
+/**********************************************************************
  *			SetMenuItemBitmaps	[USER.418]
  */
 BOOL SetMenuItemBitmaps(HMENU hMenu, WORD nPos, WORD wFlags,
@@ -1881,6 +1977,7 @@
     menu->hWndParent	  = 0;
     menu->MouseFlags	  = 0;
     menu->BarFlags	  = TRUE;
+    menu->SysFlag	  = FALSE;
     menu->Width = 100;
     menu->Height = 0;
     return hMenu;
@@ -1923,7 +2020,105 @@
 
 
 /**********************************************************************
- *			DrawMenuBar		[USER.152]
+ *			LoadMenu		[USER.150]
+ */
+HMENU LoadMenu(HINSTANCE instance, char *menu_name)
+{
+    HMENU     		hMenu;
+    HANDLE		hMenu_desc;
+    MENU_HEADER 	*menu_desc;
+
+#ifdef DEBUG_MENU
+    if ((LONG)menu_name & 0xFFFF0000L)
+	printf("LoadMenu: instance %02x, menu '%s'\n", instance, menu_name);
+    else
+	printf("LoadMenu: instance %02x, menu '%04X'\n", instance, menu_name);
+#endif
+    if (instance == (HANDLE)NULL)  instance = hSysRes;
+    if (menu_name == NULL || 
+	(hMenu_desc = RSC_LoadMenu(instance, menu_name)) == 0 ||
+	(menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc)) == NULL)
+    {
+	return 0;
+    }
+    hMenu = CreateMenu();
+    ParseMenuResource((WORD *) (menu_desc + 1), 0, hMenu);
+    return hMenu;
+}
+
+
+/**********************************************************************
+ *			GetSystemMenu		[USER.156]
+ */
+HMENU GetSystemMenu(HWND hWnd, BOOL bRevert)
+{
+    WND		*wndPtr;
+    wndPtr = WIN_FindWndPtr(hWnd);
+    if (!bRevert) {
+	return wndPtr->hSysMenu;
+	}
+    else {
+	DestroyMenu(wndPtr->hSysMenu);
+	wndPtr->hSysMenu = CopySysMenu();
+	}
+    return wndPtr->hSysMenu;
+}
+
+
+/**********************************************************************
+ *			GetMenu		[USER.157]
+ */
+HMENU GetMenu(HWND hWnd) 
+{ 
+    WND * wndPtr = WIN_FindWndPtr(hWnd);
+    if (wndPtr == NULL) return 0;
+    return wndPtr->wIDmenu;
+}
+
+/**********************************************************************
+ * 			SetMenu 	[USER.158]
+ */
+BOOL SetMenu(HWND hWnd, HMENU hMenu)
+{
+    WND * wndPtr = WIN_FindWndPtr(hWnd);
+    if (wndPtr == NULL) return FALSE;
+    wndPtr->wIDmenu = hMenu;
+    return TRUE;
+}
+
+
+/**********************************************************************
+ *			GetSubMenu		[USER.159]
+ */
+HMENU GetSubMenu(HMENU hMenu, short nPos)
+{
+    HMENU	hSubMenu;
+    LPPOPUPMENU lppop;
+    LPMENUITEM 	lpitem;
+    int		i;
+#ifdef DEBUG_MENU
+    printf("GetSubMenu (%04X, %04X) !\n", hMenu, nPos);
+#endif
+    if (hMenu == 0) return 0;
+    lppop = (LPPOPUPMENU) GlobalLock(hMenu);
+    if (lppop == NULL) return 0;
+    lpitem = lppop->firstItem;
+    for (i = 0; i < lppop->nItems; i++) {
+    	if (lpitem == NULL) break;
+    	if (i == nPos) {
+	    if (lpitem->item_flags & MF_POPUP)
+		return hSubMenu;
+	    else
+		return 0;
+	    }
+    	lpitem = (LPMENUITEM)lpitem->next;
+    	}
+    return 0;
+}
+
+
+/**********************************************************************
+ *			DrawMenuBar		[USER.160]
  */
 void DrawMenuBar(HWND hWnd)
 {
@@ -1940,31 +2135,53 @@
 
 
 /**********************************************************************
- *			LoadMenu		[USER.152]
+ *			CopySysMenu (Internal)
  */
-HMENU LoadMenu(HINSTANCE instance, char *menu_name)
+HMENU CopySysMenu()
 {
     HMENU     		hMenu;
-    HANDLE		hMenu_desc;
-    MENU_HEADER 	*menu_desc;
-
+    LPPOPUPMENU 	menu;
+    LPPOPUPMENU 	sysmenu;
 #ifdef DEBUG_MENU
-    printf("LoadMenu: instance %02x, menu '%s'\n",
-	   instance, menu_name);
+    printf("CopySysMenu entry !\n");
 #endif
-    if (menu_name == NULL || 
-	(hMenu_desc = RSC_LoadMenu(instance, menu_name)) == 0 ||
-	(menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc)) == NULL)
-    {
-	return 0;
-    }
-    hMenu = CreateMenu();
-    ParseMenuResource((WORD *) (menu_desc + 1), 0, hMenu);
-    
+    if (hSysMenu == 0) {
+	hSysMenu = LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(1));
+/*	hSysMenu = LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(SC_SYSMENU));*/
+/*	hSysMenu = LoadMenu((HINSTANCE)NULL, "SYSMENU"); */
+	if (hSysMenu == 0) {
+	    printf("SysMenu not found in system resources !\n");
+	    return (HMENU)NULL;
+	    }
+#ifdef DEBUG_MENU
+	else
+	    printf("SysMenu loaded from system resources %04X !\n", hSysMenu);
+#endif
+	}
+    hMenu = GlobalAlloc(GMEM_MOVEABLE, sizeof(POPUPMENU));
+    menu = (LPPOPUPMENU) GlobalLock(hMenu);
+    sysmenu = (LPPOPUPMENU) GlobalLock(hSysMenu);
+    if (menu != NULL && sysmenu != NULL) {
+	sysmenu->BarFlags = FALSE;
+	memcpy(menu, sysmenu, sizeof(POPUPMENU));
+	}
+    else {
+	printf("CopySysMenu // Bad SysMenu pointers !\n");
+	if (menu != NULL) {
+	    GlobalUnlock(hMenu);
+	    GlobalFree(hMenu);
+	    }
+	return (HMENU)NULL;
+	}
+    GlobalUnlock(hMenu);
+    GlobalUnlock(hSysMenu);
     return hMenu;
 }
 
 
+/**********************************************************************
+ *			ParseMenuResource (for Xlib version)
+ */
 WORD * ParseMenuResource(WORD *first_item, int level, HMENU hMenu)
 {
     WORD 	*item;
@@ -1975,12 +2192,10 @@
     level++;
     next_item = first_item;
     i = 0;
-    do
-    {
+    do {
 	i++;
 	item = next_item;
-	if (*item & MF_POPUP)
-	{
+	if (*item & MF_POPUP) {
 	    MENU_POPUPITEM *popup_item = (MENU_POPUPITEM *) item;
 	    next_item = (WORD *) (popup_item->item_text + 
 				  strlen(popup_item->item_text) + 1);
@@ -1988,20 +2203,19 @@
 	    next_item = ParseMenuResource(next_item, level, hSubMenu);
 	    AppendMenu(hMenu, popup_item->item_flags, 
 	    	hSubMenu, popup_item->item_text);
-	}
-	else
-	{
+	    }
+	else {
 	    MENU_NORMALITEM *normal_item = (MENU_NORMALITEM *) item;
 	    next_item = (WORD *) (normal_item->item_text + 
 				  strlen(normal_item->item_text) + 1);
 	    AppendMenu(hMenu, normal_item->item_flags, 
 	    	normal_item->item_id, normal_item->item_text);
+	    }
 	}
-    }
     while (!(*item & MF_END));
-
     return next_item;
 }
 
+
 #endif