Release 971130

Sat Nov 29 12:35:26 1997  Alexandre Julliard  <julliard@lrc.epfl.ch>

	* [if1632/builtin.c]
	Build a complete PE header for builtin Win32 modules.

	* [loader/pe_image.c] [loader/module.c]
	HMODULE32 now points to the loading address of the module. There
	is no longer a separate PE_MODULE structure.

Fri Nov 28 11:21:47 1997  Marcus Meissner <msmeissn@cip.informatik.uni-erlangen.de>

	* [ole/*][configure.in][Makefile.in][include/interfaces.h]
	  [if1632/olesvr32.spec][if1632/olecli32.spec]
	New directory, moved OLE stuff there.
	new .spec files for olecli32,olesvr32, some stubs added.

	* [misc/shell.c]
	Added support for extracting icons from PE dlls.

	* [misc/shellord.c][if1632/shell32.spec]
	Added a huge heap of ordinal only exported shell functions
	(will work only in Win95).

	* [loader/task.c]
	Hack to make MakeProcInstance16 work in all cases (mplayer.exe).

	* [win32/string32.c][include/string32.h]
	Obsolete, removed.

	* [windows/keyboard.c]
	Added *RegisterHotkey.

	* [objects/font.c][objects/text.c]
	Added GetFontLanguageInfo, GetTextCharsetInfo.

Wed Nov 26 18:10:40 1997  Uwe Bonnes  <bon@elektron.ikp.physik.tu-darmstadt.de>

	* [misc/network.c]
	In WNetGetConnection16 return the Drive label and not the DOS-Cwd.
	Makes Wordview 6 start on a network connected machine.

	* [controls/status.c]
	Catch a Null pointer in SW_SetText.

	* [files/dos_fs.c]
 	Add NT5 functions GetLongPathName32.

	* [files/file.c]
	Make GetTempFileName16 accept drive 0 (Current Drive) too.
	Handle more errors and be more verbose in FILE_SetDosError, fix
	an error in DeleteFile32W

	* [memory/virtual.c]
	Implement FlushViewOfFile.

	* [misc/crtdll]
	Implement _rotl and splitpath and add a stub for 
	_abnormal_termination.

	* [misc/printdrv.c]
	Stub for EnumPrinters32A.

	* [win32/newfns]
	Add Stub for QueryPerformanceFrequency, change return value
	for QueryPerformanceCounter.
 	Add stub for DeviceIoControl.

Tue Nov 25 15:55:01 1997 Martin Boehme <boehme@informatik.mu-luebeck.de>

	* [controls/combo.c] [controls/edit.c] [windows/defwnd.c]
	  [windows/winpos.c] [windows/win.c]
	Removed WIN_NO_REDRAW flag.

Tue Nov 25 13:20:35 1997  Douglas Ridgway <ridgway@taiga.v-wave.com>

	* [graphics/x11drv/bitblt.c]
	Fixed memory leak in BITBLT_GetDstArea.

Sun Nov 23 14:05:23 1997  Andreas Mohr <100.30936@germany.net>

	* [files/directory.c]
	Export windows system directory to environment.

	* [if1632/Makefile.in] [if1632/builtin.c] [if1632/w32skrnl.spec]
	  [if1632/win32s16.spec] [misc/w32scomb.c] [misc/w32skrnl.c]
	Added Win32s DLLs W32SKRNL and WIN32S16.

	* [if1632/kernel32.spec] [loader/module.c]
	Added misc functions for Win32s.

	* [if1632/kernel.spec] [loader/task.c]
	Added DefineHandleTable().

	* [scheduler/process.c]
	Fixed SetEnvironmentVariable32A() to avoid heap corruption.

Sat Nov 22 14:11:42 1997  Kristian Nielsen  <kristian.nielsen@risoe.dk>

	* [windows/painting.c]
	Fix leak in BeginPaint16() for CS_PARENTDC windows where the
	update region was not properly released.

Thu Nov 20 03:55:29 1997  Gordon Chaffee <chaffee@CS.Berkeley.EDU>

	* [loader/pe_image.c]
	Implemented forwarded DLL functions.

	* [objects/dib.c]
	Added support for 16- and 32-bit mode DIBs.
	Support negative bitmap heights.

	* [win32/process.c]
	Added stub for CreateProcess32W.

	* [win32/security.c] [include/ntdll.h]
	Added stubs for LookupAccountSid32A/W.

	* [scheduler/process.c]
	Use the size specified in the PE header for the process heap.

Mon Nov 17 00:53:35 1997  Len White <phreak@cgocable.net>

	* [msdos/int3d.c]
	New file. Stubs for int3d.

Sun Nov 16 12:30:00 PST 1997  Jason Schonberg  <schon@mti.sgi.com>

	* [include/aspi.h]
	Changed comment style from C++ to C.
diff --git a/controls/edit.c b/controls/edit.c
index a285895..b4cd3ac 100644
--- a/controls/edit.c
+++ b/controls/edit.c
@@ -84,6 +84,8 @@
 	INT32 left_margin;		/* in pixels */
 	INT32 right_margin;		/* in pixels */
 	RECT32 format_rect;
+	INT32 region_posx;		/* Position of cursor relative to region: */
+	INT32 region_posy;		/* -1: to left, 0: within, 1: to right */
 	EDITWORDBREAKPROC16 word_break_proc16;
 	EDITWORDBREAKPROC32A word_break_proc32A;
 	INT32 line_count;		/* number of lines */
@@ -1016,6 +1018,7 @@
 		INT32 line = (y - es->format_rect.top) / es->line_height + es->y_offset;
 		INT32 line_index = 0;
 		LINEDEF *line_def = es->first_line_def;
+		INT32 low, high;
 		while ((line > 0) && line_def->next) {
 			line_index += line_def->length;
 			line_def = line_def->next;
@@ -1035,11 +1038,16 @@
 		dc = GetDC32(wnd->hwndSelf);
 		if (es->font)
 			old_font = SelectObject32(dc, es->font);
-		/* FIXME: inefficient algorithm */
-		for (index = line_index + 1 ; index < line_index + line_def->net_length ; index++)
-			if (LOWORD(GetTabbedTextExtent32A(dc, es->text + line_index,
-					index - line_index, es->tabs_count, es->tabs)) >= x)
-				break;
+                    low = line_index + 1;
+                    high = line_index + line_def->net_length + 1;
+                    while (low < high - 1)
+                    {
+                        INT32 mid = (low + high) / 2;
+			if (LOWORD(GetTabbedTextExtent32A(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));
@@ -2257,14 +2265,12 @@
 		nyoff = es->line_count - 1;
 	dy = (es->y_offset - nyoff) * es->line_height;
 	if (dx || dy) {
-		if (!(wnd->flags & WIN_NO_REDRAW)) {
-			RECT32 rc1;
-			RECT32 rc;
-			GetClientRect32(wnd->hwndSelf, &rc1);
-			IntersectRect32(&rc, &rc1, &es->format_rect);
-			ScrollWindowEx32(wnd->hwndSelf, -dx, dy,
-					NULL, &rc, (HRGN32)NULL, NULL, SW_INVALIDATE);
-		}
+		RECT32 rc1;
+		RECT32 rc;
+		GetClientRect32(wnd->hwndSelf, &rc1);
+		IntersectRect32(&rc, &rc1, &es->format_rect);
+		ScrollWindowEx32(wnd->hwndSelf, -dx, dy,
+				NULL, &rc, (HRGN32)NULL, NULL, SW_INVALIDATE);
 		es->y_offset = nyoff;
 		es->x_offset += dx;
 	}
@@ -2440,8 +2446,7 @@
 	EDIT_EM_ScrollCaret(wnd, es);
 
 	/* FIXME: really inefficient */
-	if (!(wnd->flags & WIN_NO_REDRAW))
-		InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
+	InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
 }
 
 
@@ -2525,8 +2530,7 @@
 	es->flags &= ~EF_MODIFIED;
 	es->flags &= ~EF_UPDATE;
 	EDIT_BuildLineDefs_ML(wnd, es);
-	if (!(wnd->flags & WIN_NO_REDRAW))
-		InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
+	InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
 	EDIT_EM_ScrollCaret(wnd, es);
 }
 
@@ -2569,8 +2573,7 @@
 	es->flags &= ~EF_MODIFIED;
 	es->flags &= ~EF_UPDATE;
 	EDIT_BuildLineDefs_ML(wnd, es);
-	if (!(wnd->flags & WIN_NO_REDRAW))
-		InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
+	InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
 	EDIT_EM_ScrollCaret(wnd, es);
 }
 
@@ -2612,16 +2615,16 @@
 			 *	FIXME: do some GetABCCharWidth, or so
 			 *		This is just preliminary
 			 */
-			es->left_margin = es->right_margin = es->char_width;
+			es->left_margin = es->right_margin = es->char_width/4;
 		} else
-			es->left_margin = es->right_margin = es->char_width;
-		return;
+			es->left_margin = es->right_margin = es->char_width/4;
 	} else {
 		if (action & EC_LEFTMARGIN)
 			es->left_margin = left;
 		if (action & EC_RIGHTMARGIN)
 			es->right_margin = right;
 	}
+	dprintf_edit(stddeb, "EDIT_EM_SetMargins: left=%d, right=%d\n", es->left_margin, es->right_margin);
 }
 
 
@@ -2678,24 +2681,36 @@
 		es->flags |= EF_AFTER_WRAP;
 	else
 		es->flags &= ~EF_AFTER_WRAP;
-	if (!(wnd->flags & WIN_NO_REDRAW)) {
-		if (es->flags & EF_FOCUSED) {
-			LRESULT pos = EDIT_EM_PosFromChar(wnd, es, end, after_wrap);
-			SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
-		}
-		/* FIXME: little efficiency, could be better */
-		ORDER_UINT32(start, end);
-		ORDER_UINT32(start, old_start);
-		ORDER_UINT32(start, old_end);
-		ORDER_UINT32(end, old_start);
-		ORDER_UINT32(end, old_end);
-		ORDER_UINT32(old_start, old_end);
-		if (end != old_start) {
-			EDIT_InvalidateText(wnd, es, start, end);
-			EDIT_InvalidateText(wnd, es, old_start, old_end);
-		} else
-			EDIT_InvalidateText(wnd, es, start, old_end);
+	if (es->flags & EF_FOCUSED) {
+		LRESULT pos = EDIT_EM_PosFromChar(wnd, es, end, after_wrap);
+		SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
 	}
+/* This is little  bit more efficient than before, not sure if it can be improved. FIXME? */
+        ORDER_UINT32(start, end);
+        ORDER_UINT32(end, old_end);
+        ORDER_UINT32(start, old_start);
+        ORDER_UINT32(old_start, old_end);
+	if (end != old_start)
+        {
+/*
+ * One can also do 
+ *          ORDER_UINT32(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);
 }
 
 
@@ -3479,6 +3494,7 @@
 	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_posx = 0;
 	SetTimer32(wnd->hwndSelf, 0, 100, NULL);
 	return 0;
 }
@@ -3508,6 +3524,7 @@
 {
 	INT32 e;
 	BOOL32 after_wrap;
+	INT32 prex, prey;
 
 	if (GetCapture32() != wnd->hwndSelf)
 		return 0;
@@ -3516,7 +3533,10 @@
 	 *	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;
@@ -3677,7 +3697,7 @@
 		EDIT_EM_SetMargins(wnd, es, EC_USEFONTINFO, 0, 0);
 	if (es->style & ES_MULTILINE)
 		EDIT_BuildLineDefs_ML(wnd, es);
-	if (redraw && !(wnd->flags & WIN_NO_REDRAW))
+	if (redraw)
 		InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
 	if (es->flags & EF_FOCUSED) {
 		LRESULT pos;
@@ -3701,6 +3721,7 @@
 	if (text) {
 		dprintf_edit(stddeb, "\t'%s'\n", text);
 		EDIT_EM_ReplaceSel(wnd, es, FALSE, text);
+		es->x_offset = 0;
 	}
 	es->flags |= EF_MODIFIED;
 	es->flags |= EF_UPDATE;
@@ -3749,8 +3770,13 @@
  */
 static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT32 id, TIMERPROC32 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 scrolling here, like
+ *	FIXME: gotta do some vertical scrolling here, like
  *		EDIT_EM_LineScroll(wnd, 0, 1);
  */
 }