Release 940614

Tue Jun 14 08:09:14 1994  Bob Amstadt  (bob@pooh)

	* loader/selector.c (GetCurrentPDB): 
	Added trivial function GetCurrentPDB() which returns the program
	segment prefix selector.

	* memory/heap.c (HEAP_Free): 
	If free list is empty, make the freed block the free list.

Fri Jun 10 07:56:49 1994  Bob Amstadt  (bob@pooh)

	* controls/edit.c (EDIT_SetTextMsg): 
	Do not append a newline at the end of the last line.

	* windows/event.c (SetCapture): 
	Set winHasCursor if mouse capture succeeds.

Jun 13, 94 martin2@trgcorp.solucorp.qc.ca (Martin Ayotte)

	* [controls/listbox.c]
	Fix bug in listbox : InsertString should call AddString if -1.

	* [controls/menu.c]
	New function GetMenuState().

	* [controls/scroll.c] [windows/nonclient.c]
	Try to make ShowScrollBar() recalc NC_ regions. Not finished !

	* [objects/text.c]
	Add Stub for TabbedTextOut(), which temporarely call Textout().

	* [windows/keyboard.c] [windows/event.c]
	New function GetKeyBoardState() with an KeyStateTable array
		& associated handling in function EVENT_key().

Mon Jun 13 16:45:24 MET DST 1994 (erik@hacktic.nl)

        * [controls/menu.c]
        IsMenu() added.

        * [loader/library.c]
        ModuleFirst(), ModuleNext(), ModuleFindName(), ModuleFindHandle()
        added.

        * [object/gdiobj.c]
        IsGDIObject() added.

        * [miscemu/int2[56].c]
        bugfix: both didn't leave flags pushed on 16bit-stack.
        (winfile gets a bit further)

        * [miscemu/int16.c]
        Added (empty).

Sat Jun 11 22:56:48 1994 Jon Tombs (jon@esix2.us.es)
	* windows/event.c:
	Added code to drop redundant motion Events in the XEvent queue.

Thu Jun  9 10:55:55 MET DST 1994  Jochen Hein ( Hein@Student.TU-Clausthal.de )

	* [misc/main.c misc/message.c include/texts.h]
	Removed the text-constants from message.c into variables
	which may be changed from X-resources.

	* [misc/main.c misc/message.c]
	added <locale.h> and setlocale() to main.c, used toupper() in message.c

Mon, 13 Jun 94 09:41:16 -0500 Paul Bramel <paulbr@comm.mot.com>

        * controls/button.c ( [CR]B_LButton* ) 
        left rc.right at full window width so click on label also 
        activates the control (MSWin behavior)

Sat Jun 11 19:05:40 1994  Olaf Flebbe  (flebbe@tat.physik.uni-tuebingen.de)

        * include/windows.h:
          functions pointers can not be packed.
          (annoying warnings with forthcomming gcc-2.6.x)
        
        * loader/main.c (InitDLL): 
          Fixed a printf statement. (for control.exe) 

          (InitializeLoadedDLLs): 
          deleted shadow definition of  *wpnt.
          (Breaks many programs, because now COMMDLG will be
           initialized :-(

        * windows/win.c (SetWindowText): 
          added missing breaks; (PENSATE starts) 

        * windows/graphics.c (FloodFill): 
          Proper boundarys. (BANGBANG starts) FloodFile_rec should
          be rewritten.

        * objects/font.c (FONT_GetMetrics): 
          TYPO: use font->perchar only if it is defined. (WRITE starts)

Sun June 12, Peter Broadhurst (pbr@ua.nwl.ac.uk)
        controls/scroll.c:
        Fixes for improved behaviour when dragging thumb;
        Added SB_THUMBPOSITION message when thumb is released.
diff --git a/controls/button.c b/controls/button.c
index 8d96819..67de0ab 100644
--- a/controls/button.c
+++ b/controls/button.c
@@ -540,7 +540,6 @@
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
     rc.top += delta;
     rc.bottom = tm.tmHeight + delta;
-    rc.right = tm.tmHeight;
     if (PtInRect(&rc, MAKEPOINT(lParam)))
     {
 	SetFocus(hWnd);
@@ -569,7 +568,6 @@
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
     rc.top += delta;
     rc.bottom = tm.tmHeight + delta;
-    rc.right = tm.tmHeight;
 
     if (PtInRect(&rc, MAKEPOINT(lParam)))
     {
@@ -625,7 +623,6 @@
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
     rc.top += delta;
     rc.bottom = tm.tmHeight + delta;
-    rc.right = tm.tmHeight;
     if (PtInRect(&rc, MAKEPOINT(lParam)))
 	NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
 }
@@ -744,7 +741,6 @@
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
     rc.top += delta;
     rc.bottom = tm.tmHeight + delta;
-    rc.right = tm.tmHeight;
     if (PtInRect(&rc, MAKEPOINT(lParam)))
     {
 	SetFocus(hWnd);
@@ -773,7 +769,6 @@
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
     rc.top += delta;
     rc.bottom = tm.tmHeight + delta;
-    rc.right = tm.tmHeight;
 
     if (PtInRect(&rc, MAKEPOINT(lParam)))
     {
@@ -801,7 +796,6 @@
     delta = (rc.bottom - rc.top - tm.tmHeight) >> 1;
     rc.top += delta;
     rc.bottom = tm.tmHeight + delta;
-    rc.right = tm.tmHeight;
     if (PtInRect(&rc, MAKEPOINT(lParam)))
 	NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
 }
diff --git a/controls/combo.c b/controls/combo.c
index 22a1b08..ef6c3b7 100644
--- a/controls/combo.c
+++ b/controls/combo.c
@@ -103,6 +103,14 @@
 		printf("Combo WM_DESTROY %lX !\n", lphc);
 #endif
 		return DefWindowProc( hwnd, message, wParam, lParam );
+	case WM_SHOWWINDOW:
+#ifdef DEBUG_COMBO
+		printf("ComboBox WM_SHOWWINDOW hWnd=%04X !\n", hwnd);
+#endif
+		if (!(wParam == 0 && lParam == 0L)) {
+			InvalidateRect(hwnd, NULL, TRUE);
+			}
+	    break;
 	
     case WM_COMMAND:
 		wndPtr = WIN_FindWndPtr(hwnd);
diff --git a/controls/edit.c b/controls/edit.c
index 8d43172..abafcfe 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -15,9 +15,7 @@
 #include "class.h"
 #include "user.h"
 
-/*
-#define DEBUG_EDIT
-*/
+#define DEBUG_EDIT /* */
 
 #define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
 	SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
@@ -1993,7 +1991,7 @@
 	es->hText = EDIT_HEAP_REALLOC(es->hText, len + 3);
 	text = EDIT_HEAP_ADDR(es->hText);
 	strcpy(text, (char *)lParam);
-	text[len] = '\n';
+/*	text[len] = '\n'; */ /* Removed by Bob Amstadt */
 	text[len + 1] = '\0';
 	text[len + 2] = '\0';
 	EDIT_BuildTextPointers(hwnd);
diff --git a/controls/listbox.c b/controls/listbox.c
index 522131a..196cb9b 100644
--- a/controls/listbox.c
+++ b/controls/listbox.c
@@ -833,6 +833,10 @@
 	HANDLE	hTemp;
 	LPSTR	str;
 	UINT	Count;
+#ifdef DEBUG_LISTBOX
+    printf("ListBoxInsertString(%04X, %d, %08X);\n", hwnd, uIndex, newstr);
+#endif
+	if (uIndex == (UINT)-1) return ListBoxAddString(hwnd, newstr);
 	lphl = ListBoxGetWindowAndStorage(hwnd, &wndPtr);
 	if (lphl == NULL) return LB_ERR;
 	if (uIndex >= lphl->ItemsCount) return LB_ERR;
@@ -846,7 +850,7 @@
 	hTemp = USER_HEAP_ALLOC(GMEM_MOVEABLE, sizeof(LISTSTRUCT));
 	lplsnew = (LPLISTSTRUCT) USER_HEAP_ADDR(hTemp);
     if (lplsnew == NULL) {
-		printf("ListBoxAddString() // Bad allocation of new item !\n");
+		printf("ListBoxInsertString() // Bad allocation of new item !\n");
 		return LB_ERRSPACE;
 		}
 	ListBoxDefaultItem(hwnd, wndPtr, lphl, lplsnew);
@@ -862,6 +866,9 @@
 			if (str == NULL) return LB_ERRSPACE;
 			strcpy(str, newstr);
 			newstr = str;
+#ifdef DEBUG_LISTBOX
+		    printf("ListBoxInsertString // after strcpy '%s'\n", str);
+#endif
 			}
 		}
 	lplsnew->lpNext = NULL;
@@ -886,6 +893,9 @@
 		InvalidateRect(hwnd, NULL, TRUE);
 		UpdateWindow(hwnd);
 		}
+#ifdef DEBUG_LISTBOX
+    printf("ListBoxInsertString // count=%d\n", lphl->ItemsCount);
+#endif
 	return lphl->ItemsCount;
 }
 
diff --git a/controls/menu.c b/controls/menu.c
index 6470497..58a9865 100644
--- a/controls/menu.c
+++ b/controls/menu.c
@@ -845,6 +845,9 @@
 	if (lpitem == NULL) goto EndOfPaint;
 	for(i = 0; i < lppop->nItems; i++) {
 		CopyRect(&rect2, &lpitem->rect);
+#ifdef DEBUG_MENU
+		printf("StdDrawMenuBar // start left=%d\n", rect2.left);
+#endif
 		if ((lpitem->item_flags & MF_CHECKED) == MF_CHECKED) {
 			hMemDC = CreateCompatibleDC(hDC);
 			if (lpitem->hCheckBit == 0) {
@@ -856,7 +859,11 @@
 				GetObject(lpitem->hCheckBit, sizeof(BITMAP), (LPSTR)&bm);
 				}
 			BitBlt(hDC, rect2.left, rect2.top + 1,
-			bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+				bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+			rect2.left += bm.bmWidth;
+#ifdef DEBUG_MENU
+			printf("StdDrawMenuBar // MF_CHECKED bm.bmWidth=%d\n", bm.bmWidth);
+#endif
 			DeleteDC(hMemDC);
 			}
 		else {
@@ -866,6 +873,10 @@
 				GetObject(lpitem->hUnCheckBit, sizeof(BITMAP), (LPSTR)&bm);
 				BitBlt(hDC, rect2.left, rect2.top + 1,
 					bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
+				rect2.left += bm.bmWidth;
+#ifdef DEBUG_MENU
+				printf("StdDrawMenuBar // MF_UNCHECKED bm.bmWidth=%d\n", bm.bmWidth);
+#endif
 				DeleteDC(hMemDC);
 				}
 			}
@@ -898,6 +909,9 @@
 				}
 			if ((lpitem->item_flags & MF_HILITE) == MF_HILITE)
 				FillRect(hDC, &rect2, GetStockObject(BLACK_BRUSH));
+#ifdef DEBUG_MENU
+			printf("StdDrawMenuBar // rect2.left=%d\n", rect2.left);
+#endif
 			DrawText(hDC, lpitem->item_text, -1, &rect2, 
 				DT_LEFT | DT_VCENTER | DT_SINGLELINE);
 			SetTextColor(hDC, OldTextColor);
@@ -1073,13 +1087,15 @@
 		lprect->left, lprect->top, lprect->right, lprect->bottom);
 #endif
 	hOldFont = SelectObject(hDC, GetStockObject(SYSTEM_FONT));
-	LineHeight = OldHeight = SYSMETRICS_CYMENU + 1;
+	lppop->CheckWidth = 0;
+	LineHeight = OldHeight = SYSMETRICS_CYMENU + 2;
 	SetRect(&rect, lprect->left, lprect->top, 0, lprect->top + LineHeight);
 	lpitem2 = lppop->firstItem;
 	while (lpitem != NULL) {
 		lpitem = lpitem2;
 		while(rect.right < lprect->right) {
 			if (lpitem == NULL) break;
+			rect.right = rect.left;
 			if ((lpitem->item_flags & MF_BITMAP) == MF_BITMAP) {
 				hBitMap = (HBITMAP)LOWORD((LONG)lpitem->item_text);
 				GetObject(hBitMap, sizeof(BITMAP), (LPSTR)&bm);
@@ -1095,6 +1111,21 @@
 				dwRet = max(SYSMETRICS_CYMENU, (HIWORD(dwRet) + 6));
 				LineHeight = max(LineHeight, (WORD)dwRet);
 				}
+			if ((lpitem->item_flags & MF_CHECKED) == MF_CHECKED) {
+				if (lpitem->hCheckBit != 0)
+					GetObject(lpitem->hCheckBit, sizeof(BITMAP), (LPSTR)&bm);
+				else
+					GetObject(hStdCheck, sizeof(BITMAP), (LPSTR)&bm);
+				rect.right += bm.bmWidth;
+				LineHeight = max(LineHeight, bm.bmHeight);
+				}
+			else {
+				if (lpitem->hUnCheckBit != 0) {
+					GetObject(lpitem->hUnCheckBit, sizeof(BITMAP), (LPSTR)&bm);
+					rect.right += bm.bmWidth;
+					LineHeight = max(LineHeight, bm.bmHeight);
+ 					}
+				}
 			CopyRect(&lpitem->rect, &rect);
 			rect.left = rect.right;
 			lpitem = (LPMENUITEM)lpitem->next;
@@ -1112,7 +1143,7 @@
 			}
 		}
 	lppop->Width = lprect->right - lprect->left;
-	lppop->Height =  rect.bottom - lprect->top;
+	lppop->Height = rect.bottom - lprect->top;
 	lprect->bottom = lprect->top + lppop->Height;
 	CopyRect(&lppop->rect, lprect);
 #ifdef DEBUG_MENUCALC
@@ -1362,8 +1393,10 @@
 {
 	LPPOPUPMENU	menu;
 	LPMENUITEM 	lpitem;
+#ifdef DEBUG_MENU
 	printf("HiliteMenuItem(%04X, %04X, %04X, %04X);\n", 
 						hWnd, hMenu, wItemID, wHilite);
+#endif
 	menu = (LPPOPUPMENU) GlobalLock(hMenu);
 	if (menu == NULL) return FALSE;
 	lpitem = FindMenuItem(hMenu, wItemID, wHilite);
@@ -1373,6 +1406,24 @@
 
 
 /**********************************************************************
+ *			GetMenuState		[USER.250]
+ */
+WORD GetMenuState(HMENU hMenu, WORD wItemID, WORD wFlags)
+{
+	LPPOPUPMENU	menu;
+	LPMENUITEM 	lpitem;
+#ifdef DEBUG_MENU
+	printf("GetMenuState(%04X, %04X, %04X);\n", hMenu, wItemID, wFlags);
+#endif
+	menu = (LPPOPUPMENU) GlobalLock(hMenu);
+	if (menu == NULL) return -1;
+	lpitem = FindMenuItem(hMenu, wItemID, wFlags);
+	if (lpitem == NULL) return -1;
+	return lpitem->item_flags;
+}
+
+
+/**********************************************************************
  *			GetMenuItemCount		[USER.263]
  */
 WORD GetMenuItemCount(HMENU hMenu)
@@ -2186,10 +2237,20 @@
 #endif
 		lppop = (LPPOPUPMENU) GlobalLock(wndPtr->wIDmenu);
 		if (lppop == NULL) return;
-		if ((lppop->rect.bottom - lppop->rect.top) != 0) {
+		if (lppop->Height != 0) {
+			int oldHeight;
+			oldHeight = lppop->Height;
 			hDC = GetWindowDC(hWnd);
 			StdDrawMenuBar(hDC, &lppop->rect, lppop, FALSE);
 			ReleaseDC(hWnd, hDC);
+			if (oldHeight != lppop->Height) {
+				printf("DrawMenuBar // menubar changed oldHeight=%d != lppop->Height=%d\n",
+											oldHeight, lppop->Height);
+				/* Reduce ClientRect according to MenuBar height */
+				wndPtr->rectClient.top -= oldHeight;
+				wndPtr->rectClient.top += lppop->Height;
+				SendMessage(hWnd, WM_NCPAINT, 1, 0L);
+				}
 			}
 		else
 			SendMessage(hWnd, WM_NCPAINT, 1, 0L);
@@ -2319,4 +2380,17 @@
     return next_item;
 }
 
+/**********************************************************************
+ *		IsMenu(USER.358)
+ */
+BOOL IsMenu(HMENU hMenu)
+{
+	LPPOPUPMENU	menu;
 
+	menu = (LPPOPUPMENU) GlobalLock(hMenu);
+	if (menu == NULL) 
+		return FALSE;
+
+	GlobalUnlock(hMenu);
+	return TRUE;
+}
diff --git a/controls/scroll.c b/controls/scroll.c
index af1d12d..e962e8c 100644
--- a/controls/scroll.c
+++ b/controls/scroll.c
@@ -1,8 +1,10 @@
-/*
+/*		
  * Interface code to SCROLLBAR widget
  *
  * Copyright  Martin Ayotte, 1993
  *
+ * Small fixes and implemented SB_THUMBPOSITION
+ * by Peter Broadhurst, 940611
  */
 
 /*
@@ -58,6 +60,8 @@
 	RECT 	rect, rect2;
 	LPCREATESTRUCT lpCreat;
 	static RECT rectsel;
+	POINT *pt;
+	pt=(POINT*)&lParam;
 	switch(message) {
     case WM_CREATE:
 		lpCreat = (LPCREATESTRUCT)lParam;
@@ -95,15 +99,15 @@
 	
 	case WM_LBUTTONDOWN:
 		SetCapture(hWnd);
-		ScrollBarButtonDown(hWnd, SB_CTL, LOWORD(lParam), HIWORD(lParam));
+		ScrollBarButtonDown(hWnd, SB_CTL, pt->x,pt->y);
 		break;
 	case WM_LBUTTONUP:
 		ReleaseCapture();
-		ScrollBarButtonUp(hWnd, SB_CTL, LOWORD(lParam), HIWORD(lParam));
+		ScrollBarButtonUp(hWnd, SB_CTL, pt->x,pt->y);
 		break;
 
 	case WM_MOUSEMOVE:
-		ScrollBarMouseMove(hWnd, SB_CTL, wParam, LOWORD(lParam), HIWORD(lParam));
+		ScrollBarMouseMove(hWnd, SB_CTL, wParam, pt->x,pt->y);
 		break;
 	case WM_KEYDOWN:
 	case WM_KEYUP:
@@ -297,7 +301,24 @@
 	printf("ScrollBarButtonUp // x=%d y=%d\n", x, y); 
 #endif
 	lphs = GetScrollObjectStruct(hWnd, nBar);
-	lphs->ThumbActive = FALSE;
+	if(lphs->ThumbActive)
+	  {
+	    HWND hWndOwner,hWndParent;
+	    if (nBar == SB_CTL) {
+		hWndParent = GetParent(hWnd);
+		hWndOwner = lphs->hWndOwner;
+		}
+	    else {
+		hWndParent = hWnd;
+		hWndOwner = 0;
+		}
+
+	
+	    SendMessage(hWndParent, lphs->Direction, 
+			SB_THUMBPOSITION, MAKELONG(lphs->ThumbVal, hWndOwner));
+	    lphs->ThumbActive = FALSE;
+	  }
+	  
 	if (lphs->ButtonDown != 0) {
 		lphs->ButtonDown = 0;
 		if (nBar == SB_CTL) {
@@ -337,21 +358,38 @@
 		printf("ScrollBarButtonMove SB_?SCROLL // x=%d y=%d\n", x, y);
 #endif
 		}
-	if (lphs->Direction == WM_VSCROLL) {
-		int butsiz = lphs->rect.right - lphs->rect.left;
-		y = y - butsiz - (butsiz >> 1);
-		}
-	else {
-		int butsiz = lphs->rect.bottom - lphs->rect.top;
-		y = x - butsiz - (butsiz >> 1);
-		}
-	x = (y * (lphs->MaxVal - lphs->MinVal) / 
-			lphs->MaxPix) + lphs->MinVal;
+
+	if(x<lphs->rect.left||x>lphs->rect.right||
+	   y<lphs->rect.top||y>lphs->rect.bottom)
+	  {
+
 #ifdef DEBUG_SCROLL
-	printf("Scroll WM_MOUSEMOVE val=%d pix=%d\n", x, y);
+	    printf("Rejecting thumb position !\n");
+#endif
+	    lphs->ThumbVal=lphs->CurVal;/*revert to last set position*/
+	  }
+	else
+	  {
+	
+	    if (lphs->Direction == WM_VSCROLL) {
+	      int butsiz = lphs->rect.right - lphs->rect.left;
+	      y = y - butsiz - (butsiz >> 1);
+	    }
+	    else {
+	      int butsiz = lphs->rect.bottom - lphs->rect.top;
+	      y = x - butsiz - (butsiz >> 1);
+	    }
+	    if(y<0)y=0;
+	    if(y>lphs->MaxPix)y=lphs->MaxPix;
+	    lphs->ThumbVal = (y * (lphs->MaxVal - lphs->MinVal) / 
+			      lphs->MaxPix) + lphs->MinVal;
+	  }
+
+#ifdef DEBUG_SCROLL
+	printf("Scroll WM_MOUSEMOVE val=%d pix=%d\n", lphs->ThumbVal, y);
 #endif
 	SendMessage(hWndParent, lphs->Direction, 
-		SB_THUMBTRACK, MAKELONG(x, hWndOwner));
+		SB_THUMBTRACK, MAKELONG(lphs->ThumbVal, hWndOwner));
 }
 
 
@@ -442,9 +480,11 @@
 		lphs->rectDown.left = rect.right - w2;
 		}
 	if (lphs->MaxVal != lphs->MinVal)
-	lphs->CurPix = lphs->MaxPix * (abs((short)lphs->CurVal) - abs(lphs->MinVal)) / 
-    		(abs(lphs->MaxVal) - abs(lphs->MinVal));
+	lphs->CurPix = lphs->MaxPix * (lphs->CurVal - lphs->MinVal) / 
+    		(lphs->MaxVal - lphs->MinVal);
+	if(lphs->CurPix <0)lphs->CurPix=0;
 	if (lphs->CurPix > lphs->MaxPix)  lphs->CurPix = lphs->MaxPix;
+
 	hMemDC = CreateCompatibleDC(hDC);
 	if (lphs->Direction == WM_VSCROLL) {
 		GetObject(hUpArrow, sizeof(BITMAP), (LPSTR)&bm);
@@ -597,6 +637,7 @@
 		lphs->rect.right = width;
 		lphs->hWndOwner = hWnd;
 		wndPtr->VScroll = lphs;
+	    wndPtr->scroll_flags |= 0x0001;
 		if (wndPtr->dwStyle & WS_HSCROLL) height += SYSMETRICS_CYHSCROLL;
 		}
 	if (wndPtr->dwStyle & WS_HSCROLL) {
@@ -609,6 +650,7 @@
 		lphs->rect.bottom = height;
 		lphs->hWndOwner = hWnd;
 		wndPtr->HScroll = lphs;
+	    wndPtr->scroll_flags |= 0x0002;
 		}
 }
 
@@ -642,8 +684,10 @@
 	nRet = lphs->CurVal;
 	lphs->CurVal = (short)nPos;
 	if (lphs->MaxVal != lphs->MinVal)
-	lphs->CurPix = lphs->MaxPix * (abs((short)nPos) - abs(lphs->MinVal)) / 
-    		(abs(lphs->MaxVal) - abs(lphs->MinVal));
+	lphs->CurPix = lphs->MaxPix * (lphs->CurVal - lphs->MinVal) / 
+    		(lphs->MaxVal - lphs->MinVal);
+	if(lphs->CurPix <0)lphs->CurPix=0;
+
     if (lphs->CurPix > lphs->MaxPix)  lphs->CurPix = lphs->MaxPix;
 #ifdef DEBUG_SCROLL
     printf("SetScrollPos val=%d pixval=%d pixmax%d\n",
@@ -691,12 +735,15 @@
 	HDC		hDC;
     lphs = GetScrollObjectStruct(hWnd, nBar);
     if (lphs == NULL) return;
+
+/*    should a bad range be rejected here? 
+ */
     lphs->MinVal = (short)MinPos;
     lphs->MaxVal = (short)MaxPos;
     if (lphs->MaxVal != lphs->MinVal)
-	lphs->CurPix = abs(lphs->MaxVal) * 
-		(abs(lphs->CurVal) - abs(lphs->MinVal)) / 
-    		(abs(lphs->MaxVal) - abs(lphs->MinVal));
+      lphs->CurPix = lphs->MaxPix * (lphs->CurVal - lphs->MinVal) / 
+	  (lphs->MaxVal - lphs->MinVal);
+    if(lphs->CurPix <0)lphs->CurPix=0;
     if (lphs->CurPix > lphs->MaxPix)  lphs->CurPix = lphs->MaxPix;
 #ifdef DEBUG_SCROLL
     printf("SetScrollRange min=%d max=%d\n", lphs->MinVal, lphs->MaxVal);
@@ -737,32 +784,32 @@
  */
 void ShowScrollBar(HWND hWnd, WORD wBar, BOOL bFlag)
 {
-    WND  *wndPtr;
+	WND  *wndPtr;
+	printf("ShowScrollBar hWnd=%04X wBar=%d bFlag=%d\n", hWnd, wBar, bFlag);
 #ifdef DEBUG_SCROLL
-    printf("ShowScrollBar hWnd=%04X wBar=%d bFlag=%d\n", hWnd, wBar, bFlag);
+	printf("ShowScrollBar hWnd=%04X wBar=%d bFlag=%d\n", hWnd, wBar, bFlag);
 #endif
-    if (wBar == SB_CTL) {
-    	if (bFlag)
-	    ShowWindow(hWnd, SW_SHOW);
-	else
-	    ShowWindow(hWnd, SW_HIDE);
-	return;
-	}
-    wndPtr = WIN_FindWndPtr(hWnd);
-/*
-    if ((wBar == SB_VERT) || (wBar == SB_BOTH)) {
-    	if (bFlag)
-	    wndPtr->dwStyle |= WS_VSCROLL;
-	else
-	    wndPtr->dwStyle &= 0xFFFFFFFFL ^ WS_VSCROLL;
-	}
-    if ((wBar == SB_HORZ) || (wBar == SB_BOTH)) {
-    	if (bFlag)
-	    wndPtr->dwStyle |= WS_HSCROLL;
-	else
-	    wndPtr->dwStyle &= 0xFFFFFFFFL ^ WS_HSCROLL;
-	}
-*/
+	if (wBar == SB_CTL) {
+		if (bFlag)
+			ShowWindow(hWnd, SW_SHOW);
+		else
+			ShowWindow(hWnd, SW_HIDE);
+		return;
+		}
+	wndPtr = WIN_FindWndPtr(hWnd);
+	if ((wBar == SB_VERT) || (wBar == SB_BOTH)) {
+		if (bFlag)
+			wndPtr->scroll_flags != 0x0001;
+		else
+			wndPtr->scroll_flags &= 0xFFFE;
+		}
+	if ((wBar == SB_HORZ) || (wBar == SB_BOTH)) {
+		if (bFlag)
+			wndPtr->scroll_flags != 0x0002;
+		else
+			wndPtr->scroll_flags &= 0xFFFD;
+		}
+	SetWindowPos(hWnd, 0, 0, 0, 0, 0, 
+		SWP_NOZORDER | SWP_NOMOVE | 
+		SWP_NOSIZE | SWP_FRAMECHANGED);
 }
-
-