diff -u -w -b -r -N ./Older/ChangeLog ./Newer/ChangeLog
--- ./Older/ChangeLog	Thu May  6 12:11:39 2004
+++ ./Newer/ChangeLog	Thu May  6 13:22:32 2004
@@ -1,3 +1,13 @@
+2004-05-06 13:18  MA Garcias <ma.garcias@tragnarion.com>
+
+        * Headers/win32/WIN32DragView.h
+        Source/win32/WIN32DragView.m
+        Source/win32/WIN32Server.m (- dragInfo)
+        Implemented internal drag and drop, mostly ported from XGDragView
+        * Source/win32/WIN32ServerEvent.m
+        Added handling of WM_MOVE and WM_SIZE events for synchronization
+        of win32 events with frontend.
+
 2004-03-30 01:49  Alexander Malmberg <alexander@malmberg.org>
 
 	* Source/x11/XGGLFormat.m (-initWithAttributes:): Fix handling of
diff -u -w -b -r -N ./Older/Headers/win32/WIN32DragView.h ./Newer/Headers/win32/WIN32DragView.h
--- ./Older/Headers/win32/WIN32DragView.h	Thu Jan  1 01:00:00 1970
+++ ./Newer/Headers/win32/WIN32DragView.h	Mon May  3 12:22:28 2004
@@ -0,0 +1,101 @@
+/* -*- mode: objc; fill-column: 75; c-style: zombie -*- */
+/**
+    @file    WIN32DragView.h
+    @author  MA Garcias <ma.garcias@tragnarion.com>
+    @brief   Drag and Drop code for WIN32 backends
+    @brief   $Id$
+
+    View that is dragged during drag and drop
+    A class that implements the NSDraggingInfo protocol
+
+    This file is distributed under the terms set forth in the included
+    LICENSE file. If this file is not included in the distribution,
+    please contact info@tragnarion.com
+*/
+
+#include <AppKit/NSCell.h>
+#include <AppKit/NSEvent.h>
+#include <Foundation/NSGeometry.h>
+
+#include "win32/WIN32Server.h"
+
+#define NSDragOperationIgnoresModifiers 0xffff
+
+void GSEnsureDndIsInitialized( void );
+
+/**
+    The object that is dragged over the screen
+    It hijacks the event loop and manages the complete
+    drag and drop sequence
+*/
+@interface WIN32DragView : NSView <NSDraggingInfo>
+{
+    NSCell          *dragCell;          // the graphics that is dragged
+    NSPasteboard    *dragPasteboard;    // the pasteboard with the dragged data
+    NSPoint         dragPoint;          // in base coordinates, only valid when dragWindow != nil
+    HWND            dragHwnd;           // hwnd of the dragging window
+
+    /* information used in the drag and drop event loop */
+    NSPoint         offset;             // offset of image w.r.t. cursor
+    NSPoint         dragPosition;       // current drag position in screen coordinates
+    NSPoint         newPosition;        // drag position, not yet processed
+    int             wx, wy;             // position of drag image window in win32 coordinates
+
+    int             dragSequence;
+    id              dragSource;         // the NSObject source of the dragging
+
+    id              dragDestination;    // the current NSObject destination of the dragging
+
+    unsigned int    dragMask;           // Operations supported by the source
+    unsigned int    operationMask;      // user specified operation mask (key modifiers).
+                                        // this is either a mask of type _NSDragOperation,
+                                        // or NSDragOperationIgnoresModifiers, which
+                                        // is defined as 0xffff
+    HWND            targetHwnd;         // current window (HWND) target of the drag operation
+    unsigned int    targetMask;         // Operations supported by the target, only valid if
+                                        // targetIsDndAware is true
+
+    id              dragWindow;         // NSWindow in this application that is the current target
+    BOOL            dragExternal;       // YES if target and source are in a different application
+    BOOL            isDragging;         // YES if we are currently dragging
+    BOOL            slideBack;          // slide the image back when drag fails?
+
+    NSMutableDictionary *cursors;
+}
++ (WIN32DragView*) sharedDragView;
+- (BOOL) isDragging;
+
+// TODO: external drag operation
+//- (void) updateDragInfoFromEvent: (NSEvent *)event;
+//- (void) resetDragInfo;
+
+// Local drag operation
+- (void) resetDragInfo;
+- (void) dragImage: (NSImage*) anImage
+                at: (NSPoint) screenLocation
+            offset: (NSSize) initialOffset
+             event: (NSEvent*) event
+        pasteboard: (NSPasteboard*) pboard
+            source: (id) sourceObject
+         slideBack: (BOOL) slideFlag;
+- (void) postDragEvent: (NSEvent *)theEvent;
+
+// Private operations
+- (void) _sendLocalEvent: (GSAppKitSubtype) subtype
+                  action: (NSDragOperation) action
+                position: (NSPoint) eventLocation
+               timestamp: (NSTimeInterval) time
+                toWindow: (NSWindow*) dWindow;
+
+- (void) _setCursor;
+- (void) _handleDrag: (NSEvent*) theEvent;
+- (void) _handleEventDuringDragging: (NSEvent*) theEvent;
+- (void) _updateAndMoveImageToCorrectPosition;
+- (void) _moveDraggedImageToNewPosition;
+- (void) _slideDraggedImageTo: (NSPoint) screenPoint
+                numberOfSteps: (int) steps
+               waitAfterSlide: (BOOL) waitFlag;
+- (HWND) _windowAcceptingDnDUnderX: (int) x
+                                 Y: (int) y;
+
+@end
diff -u -w -b -r -N ./Older/Headers/win32/WIN32Geometry.h ./Newer/Headers/win32/WIN32Geometry.h
--- ./Older/Headers/win32/WIN32Geometry.h	Fri Apr  2 15:28:33 2004
+++ ./Newer/Headers/win32/WIN32Geometry.h	Tue May  4 12:31:16 2004
@@ -125,7 +125,7 @@
   h = rect.bottom - rect.top;
 
   p1.x = p.x;
-  p1.y = screen_height - p.y + h;
+  p1.y = screen_height - p.y - h; // [MA] was: + h --why?
   return p1;
 }
 
diff -u -w -b -r -N ./Older/Headers/win32/WIN32Server.h ./Newer/Headers/win32/WIN32Server.h
--- ./Older/Headers/win32/WIN32Server.h	Fri Apr  2 15:28:33 2004
+++ ./Newer/Headers/win32/WIN32Server.h	Thu May  6 13:02:16 2004
@@ -49,6 +49,5 @@
   HGDIOBJ old;
   MINMAXINFO minmax;
 } WIN_INTERN;
-
 
 #endif /* _WIN32Server_h_INCLUDE */
diff -u -w -b -r -N ./Older/Source/win32/GNUmakefile ./Newer/Source/win32/GNUmakefile
--- ./Older/Source/win32/GNUmakefile	Fri Apr  2 15:28:20 2004
+++ ./Newer/Source/win32/GNUmakefile	Wed Apr 21 10:49:40 2004
@@ -42,6 +42,7 @@
 # The Objective-C source files to be compiled
 win32_OBJC_FILES = \
 WIN32Server.m  \
+WIN32DragView.m  \
 WIN32ServerEvent.m
 
 -include GNUmakefile.preamble
diff -u -w -b -r -N ./Older/Source/win32/WIN32DragView.m ./Newer/Source/win32/WIN32DragView.m
--- ./Older/Source/win32/WIN32DragView.m	Thu Jan  1 01:00:00 1970
+++ ./Newer/Source/win32/WIN32DragView.m	Tue May  4 12:17:15 2004
@@ -0,0 +1,1074 @@
+/* -*- mode: objc; fill-column: 75; c-style: zombie -*- */
+/**
+    @file    WIN32DragView.m
+    @author  MA Garcias <ma.garcias@tragnarion.com>
+    @brief   Drag and Drop code for WIN32 backends
+    @brief   $Id$
+
+    ...
+
+    This file is distributed under the terms set forth in the included
+    LICENSE file. If this file is not included in the distribution,
+    please contact info@tragnarion.com
+*/
+
+#include <AppKit/NSApplication.h>
+#include <AppKit/NSCursor.h>
+#include <AppKit/NSImage.h>
+#include <AppKit/NSPasteboard.h>
+#include <AppKit/NSView.h>
+#include <AppKit/NSWindow.h>
+
+#include <AppKit/NSImageView.h>
+
+#include <Foundation/NSDebug.h>
+#include <Foundation/NSThread.h>
+
+#include "win32/WIN32Server.h"
+#include "win32/WIN32Geometry.h"
+#include "win32/WIN32DragView.h"
+
+#define DWZ                 48  // Size of the dragged window
+#define SLIDE_TIME_STEP     .02 // time step for image sliding
+#define SLIDE_NR_OF_STEPS   20  // #steps in image sliding
+
+/**
+    helper window class for the shared drag view
+*/
+@interface WIN32RawWindow : NSWindow
+@end
+
+@interface NSCursor (BackendPrivate)
+- (void *) _cid;
+- (void) _setCid: (void *)val;
+@end
+
+//  DRAG AND DROP SUPPORT
+
+@implementation WIN32DragView
+
+static WIN32DragView *sharedDragView = nil;
+
+/**
+    access to shared instance
+*/
++ (WIN32DragView*) sharedDragView
+{
+    if( sharedDragView == nil )
+    {
+        sharedDragView = [WIN32DragView new];
+    }
+    return sharedDragView;
+}
+
+/**
+    initialize shared window
+*/
+- (id) init
+{
+    self = [super init];
+    if( self != nil )
+    {
+        NSRect winRect = { { 0, 0 }, { DWZ, DWZ } };
+        WIN32RawWindow *sharedDragWindow = [WIN32RawWindow alloc];
+
+        dragCell = [[NSCell alloc] initImageCell: nil];
+        [dragCell setBordered: NO];
+
+        [sharedDragWindow initWithContentRect: winRect
+                                    styleMask: NSBorderlessWindowMask
+                                      backing: NSBackingStoreNonretained
+                                        defer: NO];
+        [sharedDragWindow setContentView: self];
+
+        // Cache the hwnd of our window for later use
+        int winnum = [sharedDragWindow windowNumber];
+        dragHwnd = (HWND) winnum;
+
+        NSDebugLLog( @"NSDragging", @"init WIN32DragView winnum %x", winnum );
+
+        RELEASE( self );
+    }
+
+    return self;
+}
+
+/**
+    return drag and drop state
+*/
+- (BOOL) isDragging
+{
+    return isDragging;
+}
+
+//
+//  Drag operation local
+//
+
+/**
+    Handle image drag and drop (inherited from NSView)
+
+    Initiates a dragging operation by the receiver allows the user to drag
+    arbitrary data with an specified icon into any application that has
+    window or view objects that accept dragged data. Invoked only within
+    the mouseDown: or mouseDragged: events
+*/
+- (void) dragImage: (NSImage*) anImage
+                at: (NSPoint) screenLocation
+            offset: (NSSize) initialOffset
+             event: (NSEvent*) event
+        pasteboard: (NSPasteboard*) pboard
+            source: (id) sourceObject
+         slideBack: (BOOL) slideFlag
+{
+    if( anImage == nil )
+    {
+        anImage = [NSImage imageNamed: @"common_Close"];
+    }
+
+    [dragCell setImage: anImage];
+
+    ASSIGN( dragPasteboard, pboard );
+    dragSource = RETAIN( sourceObject );
+    dragSequence = [event timestamp];
+    dragExternal = NO;
+    slideBack = slideFlag;
+
+    NSDebugLLog( @"NSDragging", @"Start drag with %@", [pboard types] );
+
+    if( [pboard availableTypeFromArray: GSGetDragTypes( sourceObject )] )
+        NSDebugLLog( @"NSDragging", @"pb availableTypeFromArray: YES");
+
+    //typelist = mimeTypeForPasteboardType( XDPY, [self zone], [pboard types] );
+
+    [self _handleDrag: event];
+
+    //NSZoneFree( [self zone], typelist );
+    //typelist = NULL;
+
+    RELEASE( dragSource );
+}
+
+/**
+    destroy retained objects at end of dragging session
+*/
+- (void) resetDragInfo
+{
+  DESTROY( dragPasteboard );
+}
+
+/**
+    Operation after dragging
+    Derived from NSObject (DragInfoBackend) defined in NSWindow.m
+    It is called by NSWindow in sendEvent:
+*/
+- (void) postDragEvent: (NSEvent *)theEvent
+{
+    if( [theEvent subtype] == GSAppKitDraggingStatus )
+    {
+        // NSEvent data2 field encodes the NSDragOperation
+        NSDragOperation action = [theEvent data2];
+        if( dragExternal )
+        {
+            // TODO: dnd send status
+        }
+        else
+        {
+            if( action != targetMask )
+            {
+                targetMask = action;
+                [self _setCursor];
+            }
+        }
+    }
+    else if( [theEvent subtype] == GSAppKitDraggingFinished )
+    {
+        NSDebugLLog( @"NSDragging",
+                     @"postDragEvent: GSAppKitDraggingFinished" );
+        if( dragExternal )
+        {
+            // TODO: dnd send finished
+        }
+    }
+    else
+    {
+        NSDebugLLog( @"NSDragging",
+                     @"Internal: unhandled post external event" );
+    }
+}
+
+/* Private Functions */
+
+/**
+    Send event to the window used for displaying the dragview
+    It skips the event loop and posts the message directly to the
+    window parameter if in the same application
+*/
+- (void) _sendLocalEvent: (GSAppKitSubtype) subtype
+                  action: (NSDragOperation) action
+                position: (NSPoint) eventLocation
+               timestamp: (NSTimeInterval) time
+                toWindow: (NSWindow*) dWindow
+{
+    NSEvent *e;
+    NSGraphicsContext *context = GSCurrentContext();
+
+    int winnum = [dWindow windowNumber];
+
+    eventLocation = MSScreenPointToGS( eventLocation.x, eventLocation.y );
+    eventLocation = [dWindow convertScreenToBase: eventLocation];
+
+    e = [NSEvent otherEventWithType: NSAppKitDefined
+                           location: eventLocation
+                      modifierFlags: 0
+                          timestamp: GetTickCount()
+                       windowNumber: winnum
+                            context: context
+                            subtype: subtype
+                              data1: (int) targetHwnd
+                              data2: action];
+    [dWindow sendEvent: e];
+}
+
+/**
+    updates the cursor according to the state of the dragging
+    It will not save the current cursor,
+    if you want to keep the original you have to save it yourself.
+    The code recogines 4 cursors:
+    NONE    when the source does not allow dragging
+    COPY    when the current operation is ONLY Copy
+    LINK    when the current operation is ONLY Link
+    GENERIC all other cases
+    And two colors:
+    GREEN   when the target accepts the drop
+    BLACK   when the target does not accept the drop
+*/
+- (void) _setCursor
+{
+    NSCursor *newCursor;
+    NSString *name;
+    NSString *iname;
+    int mask;
+
+    mask = dragMask & operationMask;
+
+    if( targetHwnd )
+    {
+        mask &= targetMask;
+    }
+
+    NSDebugLLog( @"NSDragging",
+                 @"drag, operation, target mask = (%x, %x, %x), dnd aware = %d\n",
+                 dragMask, operationMask, targetMask,
+                 ( targetHwnd != 0) );
+
+    if( cursors == nil )
+    {
+        cursors = RETAIN( [NSMutableDictionary dictionary] );
+    }
+
+    name = nil;
+    newCursor = nil;
+
+    switch( mask )
+    {
+    case NSDragOperationNone:
+        name = @"NoCursor";
+        iname = @"common_noCursor";
+        break;
+
+    case NSDragOperationCopy:
+        name = @"CopyCursor";
+        iname = @"common_copyCursor";
+        break;
+
+    case NSDragOperationLink:
+        name = @"LinkCursor";
+        iname = @"common_linkCursor";
+        break;
+
+    case NSDragOperationGeneric:
+        break;
+
+    default:
+        // FIXME: Should not happen, add warning?
+        break;
+    }
+
+    if( name != nil )
+    {
+        newCursor = [cursors objectForKey: name];
+        if( newCursor == nil )
+        {
+            NSImage *image = [NSImage imageNamed: iname];
+            newCursor = [[NSCursor alloc] initWithImage: image];
+            [cursors setObject: newCursor forKey: name];
+            RELEASE(newCursor);
+        }
+    }
+
+    if( newCursor == nil )
+    {
+        name = @"ArrowCursor";
+        newCursor = [cursors objectForKey: name];
+        if( newCursor == nil )
+        {
+            // Make our own arrow cursor, since we want to color it
+            void *c;
+            newCursor = [[NSCursor alloc] initWithImage: nil];
+            [GSCurrentServer() standardcursor: GSArrowCursor: &c];
+            [newCursor _setCid: c];
+            [cursors setObject: newCursor forKey: name];
+            RELEASE( newCursor );
+        }
+    }
+
+    [newCursor set];
+
+    if( ( targetHwnd != 0 ) && mask != NSDragOperationNone )
+    {
+        [GSCurrentServer() setcursorcolor: [NSColor greenColor]
+                                         : [NSColor blackColor]
+                                         : [newCursor _cid]];
+    }
+    else
+    {
+        [GSCurrentServer() setcursorcolor: [NSColor blackColor]
+                                         : [NSColor whiteColor]
+                                         : [newCursor _cid]];
+    }
+}
+
+/**
+    initialize the dragview before it is put to the screen
+    It only initializes the instance variables that have to do with
+    moving the image over the screen and variables that are used to
+    keep track where they are
+    So it is typically used just before the dragview is actually displayed.
+    Pre conditions:
+    - dragCell is initialized with the image to drag.
+//  (XGDragView)
+//  - typelist is initialized with the dragging types
+    Post conditions:
+    - all instance variables pertaining to moving the window are initialized
+    - all instance variables pertaining to win32 are initialized
+*/
+- (void) _setupWindow: (NSPoint) dragStart
+{
+    NSSize imageSize = [[dragCell image] size];
+    offset = NSMakePoint( imageSize.width / 2.0, imageSize.height / 2.0 );
+
+    [_window setFrame: NSMakeRect( dragStart.x - offset.x,
+                                   dragStart.y - offset.y,
+                                   imageSize.width, imageSize.height )
+              display: YES];
+
+    // ...
+    // not resizing the content view!
+    // is it because of the backend painting?
+
+    POINT p = GSScreenPointToMS( dragStart );
+    wx = p.x;
+    wy = p.y;
+
+    NSDebugLLog( @"NSDragging", @"_setupWindow: %@", NSStringFromPoint( dragStart ) );
+
+    dragPosition = dragStart;
+    newPosition = dragStart;
+
+    // ...
+    // display only the image
+    // not implemented in win32 !
+    //int winnum = [_window windowNumber];
+    //[GSServerForWindow(_window) restrictWindow: winnum
+    //                                   toImage: [dragCell image]];*/
+
+    [_window orderFront: nil];
+}
+
+/**
+    ...
+    displaying the image cell
+    restrictWindow: doesn't currently work in win32 backend (but hopefully will)
+*/
+- (void) drawRect: (NSRect) aRect
+{
+    NSDebugLLog( @"NSDragging", @"drawRect: %@", NSStringFromRect(aRect) );
+    [dragCell drawWithFrame: [self frame] inView: self];
+}
+
+/**
+    Updates the operationMask by examining modifier keys
+    pressed during theEvent.
+
+    If the current value of operationMask == NSDragOperationIgnoresModifiers
+    it will return immediately without updating the operationMask
+
+    This method will return YES if the operationMask
+    is changed, NO if it is still the same.
+*/
+- (BOOL) _updateOperationMask: (NSEvent*) theEvent
+{
+    unsigned int mod = [theEvent modifierFlags];
+    unsigned int oldOperationMask = operationMask;
+
+    if( operationMask == NSDragOperationIgnoresModifiers )
+    {
+        return NO;
+    }
+
+    if( mod & NSControlKeyMask )
+    {
+        operationMask = NSDragOperationLink;
+    }
+    else if( mod & NSAlternateKeyMask )
+    {
+        operationMask = NSDragOperationCopy;
+    }
+    else if( mod & NSCommandKeyMask )
+    {
+        operationMask = NSDragOperationGeneric;
+    }
+    else
+    {
+        operationMask = NSDragOperationAll;
+    }
+
+    return( operationMask != oldOperationMask );
+}
+
+/**
+    The dragging support works by hijacking the NSApp event loop.
+
+    - this function loops until the dragging operation is finished
+      and consumes all NSEvents during the drag operation.
+    - It sets up periodic events.  The drawing and communication
+      with DraggingSource and DraggingTarget is handled in the
+      periodic event code.  The use of periodic events is purely
+      a performance improvement.  If no periodic events are used
+      the system can not process them all on time.
+      At least on a 333Mhz laptop, using fairly simple
+      DraggingTarget code.
+*/
+- (void) _handleDrag: (NSEvent*) theEvent
+{
+    NSWindow *eventWindow = [theEvent window];
+    NSDate *theDistantFuture = [NSDate distantFuture];
+    NSImage *dragImage = [dragCell image];
+    NSPoint startPoint;
+    unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask |
+                             NSLeftMouseDraggedMask | NSMouseMovedMask |
+                             NSPeriodicMask | NSAppKitDefinedMask |
+                             NSFlagsChangedMask;
+
+    // storing values, to restore after we have finished
+    NSCursor *cursorBeforeDrag = [NSCursor currentCursor];
+
+    // Unset the target window
+    targetHwnd = 0;
+    targetMask = NSDragOperationAll;
+
+    isDragging = YES;
+    startPoint = [eventWindow convertBaseToScreen: [theEvent locationInWindow]];
+
+    [self _setupWindow: startPoint];
+
+    // Notify the source that dragging has started
+    if( [dragSource respondsToSelector: @selector(draggedImage:beganAt:)] )
+    {
+        [dragSource draggedImage: dragImage beganAt: startPoint];
+    }
+
+    NSDebugLLog( @"NSDragging", @"Drag window origin %d %d\n", wx, wy );
+
+    // Setup up the masks for the drag operation
+    if( [dragSource respondsToSelector:
+        @selector(ignoreModifierKeysWhileDragging)] &&
+        [dragSource ignoreModifierKeysWhileDragging] )
+    {
+        operationMask = NSDragOperationIgnoresModifiers;
+    }
+    else
+    {
+        operationMask = 0;
+        [self _updateOperationMask: theEvent];
+    }
+
+    dragMask = [dragSource draggingSourceOperationMaskForLocal: !dragExternal];
+
+    // capture the mouse
+    [GSServerForWindow(eventWindow) capturemouse: (int) [eventWindow windowNumber]];
+
+    // setup the event loop
+    [self _updateAndMoveImageToCorrectPosition];
+    [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: 0.03];
+
+    NSDebugLLog( @"NSDragging", @"Entering the drag loop\n" );
+
+    // loop handling all events during drag operation
+    while( [theEvent type] != NSLeftMouseUp )
+    {
+        [self _handleEventDuringDragging: theEvent];
+        theEvent = [NSApp nextEventMatchingMask: eventMask
+                                      untilDate: theDistantFuture
+                                         inMode: NSEventTrackingRunLoopMode
+                                        dequeue: YES];
+    }
+
+    [NSEvent stopPeriodicEvents];
+    [self _updateAndMoveImageToCorrectPosition];
+
+    // release the mouse
+    [GSServerForWindow(eventWindow) releasemouse];
+
+    // Deposit the drop
+    if( ( targetHwnd != 0 ) &&
+        ( ( targetMask & dragMask & operationMask ) != NSDragOperationNone ) )
+    {
+        [_window orderOut: nil];
+        [cursorBeforeDrag set];
+
+        NSDebugLLog( @"NSDragging", @"sending dnd drop\n" );
+
+        if( !dragExternal )
+        {
+            [self _sendLocalEvent: GSAppKitDraggingDrop
+                           action: 0
+                         position: NSZeroPoint
+                        timestamp: GetTickCount()
+                         toWindow: dragWindow];
+        }
+        else
+        {
+            // TODO: external drag - send drop event
+        }
+
+        if( [dragSource respondsToSelector:
+                @selector(draggedImage:endedAt:deposited:)] )
+        {
+            NSPoint point;
+            point = [theEvent locationInWindow];
+            point = [[theEvent window] convertBaseToScreen: point];
+
+            [dragSource draggedImage: dragImage
+                             endedAt: point
+                           deposited: YES];
+        }
+    }
+    else
+    {
+        NSDebugLLog( @"NSDragging",
+                     @"drag, operation, target mask = (%x, %x, %x), dnd aware = %d\n",
+                     dragMask, operationMask, targetMask,
+                     ( targetHwnd != 0) );
+
+        // no target window OR no dragging operation:
+        // return image back where it came from
+        if( slideBack )
+        {
+            [self slideDraggedImageTo: startPoint];
+        }
+        [_window orderOut: nil];
+
+        [cursorBeforeDrag set];
+
+        NSDebugLLog( @"NSDragging", @"not sending dnd drop\n" );
+
+        if( [dragSource respondsToSelector:
+            @selector(draggedImage:endedAt:deposited:)] )
+        {
+            NSPoint point;
+            point = [theEvent locationInWindow];
+            point = [[theEvent window] convertBaseToScreen: point];
+
+            [dragSource draggedImage: dragImage
+                             endedAt: point
+                           deposited: NO];
+        }
+    }
+
+    isDragging = NO;
+}
+
+/**
+    handle the events for the event loop during drag and drop
+*/
+- (void) _handleEventDuringDragging: (NSEvent*) theEvent
+{
+    switch( [theEvent type] )
+    {
+    case NSAppKitDefined:
+    {
+        GSAppKitSubtype sub = [theEvent subtype];
+        switch( sub )
+        {
+            // Keep window up-to-date with its current position.
+            case GSAppKitWindowMoved:
+                [NSApp sendEvent: theEvent];
+                break;
+
+            case GSAppKitDraggingStatus:
+                NSDebugLLog(@"NSDragging", @"got GSAppKitDraggingStatus\n");
+                // is local event?
+                if( [theEvent data1] == (int) targetHwnd )
+                {
+                    unsigned int newTargetMask = [theEvent data2];
+                    if( newTargetMask != targetMask )
+                    {
+                        targetMask = newTargetMask;
+                        [self _setCursor];
+                    }
+                }
+                break;
+
+            case GSAppKitDraggingFinished:
+                NSLog( @"Internal: got GSAppKitDraggingFinished out of seq" );
+                break;
+
+            case GSAppKitWindowFocusIn:
+            case GSAppKitWindowFocusOut:
+            case GSAppKitWindowLeave:
+            case GSAppKitWindowEnter:
+                // ignore these messages
+                break;
+
+            default:
+                NSLog( @"Internal: dropped NSAppKitDefined (%d) event", sub );
+                break;
+        }
+        break;
+    }
+    case NSMouseMoved:
+    case NSLeftMouseDragged:
+    case NSLeftMouseDown:
+    case NSLeftMouseUp:
+    {
+        newPosition = [[theEvent window] convertBaseToScreen: [theEvent locationInWindow]];
+        break;
+    }
+    // if flags change (?) send update to allow destination to take note
+    case NSFlagsChanged:
+        if( [self _updateOperationMask: theEvent] )
+        {
+            if( dragWindow )
+            {
+              [self _sendLocalEvent: GSAppKitDraggingUpdate
+                             action: dragMask & operationMask
+                           position: NSMakePoint( wx + offset.x, wy + offset.y )
+                          timestamp: GetTickCount()
+                           toWindow: dragWindow];
+            }
+            else
+            {
+                // TODO: send position message to targetHwnd
+            }
+
+            [self _setCursor];
+        }
+        break;
+
+    case NSPeriodic:
+        if( ( newPosition.x != dragPosition.x ) ||
+            ( newPosition.y != dragPosition.y ) )
+        {
+            [self _updateAndMoveImageToCorrectPosition];
+        }
+        break;
+
+    default:
+        NSLog( @"Internal: dropped event (%d) during dragging",
+               [theEvent type] );
+    }
+}
+
+/**
+    Move the drag image and update all associated data
+*/
+- (void) _updateAndMoveImageToCorrectPosition
+{
+    NSWindow *oldDragWindow;
+    BOOL     oldDragExternal;
+    HWND     mouseHwnd;
+    BOOL     changeCursor = NO;
+
+    [self _moveDraggedImageToNewPosition];
+
+    // store old values for later comparison
+    oldDragWindow = dragWindow;
+    oldDragExternal = dragExternal;
+
+    // determine MS window under the mouse
+    mouseHwnd = [self _windowAcceptingDnDUnderX: wx + offset.x
+                                              Y: wy + offset.y];
+
+    // determine target NSWindow under the mouse
+    if( mouseHwnd != 0 )
+    {
+        dragWindow = GSWindowWithNumber( (int) mouseHwnd );
+    }
+    else
+    {
+        dragWindow = nil;
+    }
+
+    // If we have are not hovering above a window that we own
+    // we are dragging to an external application.
+    dragExternal = ( mouseHwnd != 0 ) && ( dragWindow == nil );
+
+    if( dragWindow )
+    {
+        dragPoint = [dragWindow convertScreenToBase: dragPosition];
+    }
+
+    // if the window under the mouse is different from the previous one
+    // send exit message
+    if( ( mouseHwnd != targetHwnd ) && targetHwnd )
+    {
+        if( oldDragWindow )
+        {
+            [self _sendLocalEvent: GSAppKitDraggingExit
+                           action: dragMask & operationMask
+                         position: NSZeroPoint
+                        timestamp: dragSequence
+                         toWindow: oldDragWindow];
+        }
+        else
+        {
+            // TODO: send leave message to targetHwnd
+        }
+    }
+
+    // Reset drag mask when we switch from external to internal or back
+    if( oldDragExternal != dragExternal )
+    {
+        unsigned int newMask;
+        newMask = [dragSource draggingSourceOperationMaskForLocal: dragExternal];
+        if( newMask != dragMask )
+        {
+            dragMask = newMask;
+            changeCursor = YES;
+        }
+    }
+
+    // same window, sending update
+    if( mouseHwnd == targetHwnd && targetHwnd )
+    {
+        if( dragWindow )
+        {
+            [self _sendLocalEvent: GSAppKitDraggingUpdate
+                           action: dragMask & operationMask
+                         position: NSMakePoint( wx + offset.x, wy + offset.y )
+                        timestamp: GetTickCount()
+                         toWindow: dragWindow];
+        }
+        else
+        {
+            // TODO: send position message to targetHwnd
+        }
+    }
+    else if( mouseHwnd != 0 )
+    {
+        if( dragWindow )
+        {
+            [self _sendLocalEvent: GSAppKitDraggingEnter
+                           action: dragMask
+                         position: NSMakePoint( wx + offset.x, wy + offset.y )
+                        timestamp: GetTickCount()
+                         toWindow: dragWindow];
+        }
+        else
+        {
+            // TODO: send enter to mouse window
+            // TODO: send position to mouse window
+        }
+    }
+
+    if( targetHwnd != mouseHwnd )
+    {
+        targetHwnd = mouseHwnd;
+        changeCursor = YES;
+    }
+
+    if( changeCursor )
+    {
+        [self _setCursor];
+    }
+}
+
+/**
+    Move the dragged image immediately to the position indicated by
+    the instance variable newPosition
+    In doing so it will update the (wx, wy) and dragPosition instance variables
+*/
+- (void) _moveDraggedImageToNewPosition
+{
+    NSDebugLLog( @"NSDragging", @"_moveDraggedImageToNewPosition: %f, %f\n",
+                 newPosition.x - offset.x,
+                 newPosition.y - offset.y );
+
+    wx += (int) ( newPosition.x - dragPosition.x );
+    wy += (int) ( dragPosition.y - newPosition.y );
+
+    // We use this instead of the simpler 'dragPosition = newPosition'
+    // because we want to keep the dragPosition in sync with (wx, wy)
+    // and (wx, wy) are integers.
+    dragPosition.x += (float) ( (int) newPosition.x - dragPosition.x );
+    dragPosition.y += (float) ( (int) newPosition.y - dragPosition.y );
+
+    NSSize imageSize = [[dragCell image] size];
+
+    [_window setFrame: NSMakeRect( newPosition.x - offset.x,
+                                   newPosition.y - offset.y,
+                                   imageSize.width, imageSize.height )
+              display: YES];
+
+    // ... not using movewindow: the backend doesn't properly handle redrawing
+/*  [GSServerForWindow(_window) movewindow: NSMakePoint( newPosition.x - offset.x,
+                                                         newPosition.y - offset.y )
+                                          : (int) dragHwnd];*/
+}
+
+- (void) _slideDraggedImageTo: (NSPoint) screenPoint
+                numberOfSteps: (int) steps
+               waitAfterSlide: (BOOL) waitFlag
+{
+    // If we do not need multiple redrawing, just move the image immediately
+    // to its desired spot.
+    if( steps < 2 )
+    {
+        newPosition = screenPoint;
+        [self _moveDraggedImageToNewPosition];
+    }
+    else
+    {
+        [NSEvent startPeriodicEventsAfterDelay: 0.02 withPeriod: SLIDE_TIME_STEP];
+
+        // Use the event loop to redraw the image repeatedly.
+        // Using the event loop to allow the application to process
+        // expose events.
+        while( steps )
+        {
+            NSEvent *theEvent = [NSApp nextEventMatchingMask: NSPeriodicMask
+                                                   untilDate: [NSDate distantFuture]
+                                                      inMode: NSEventTrackingRunLoopMode
+                                                     dequeue: YES];
+            if( [theEvent type] != NSPeriodic )
+            {
+                NSDebugLLog( @"NSDragging",
+                             @"Unexpected event type: %d during slide",
+                             [theEvent type] );
+            }
+            newPosition.x = ( screenPoint.x + ( (float) steps - 1.0 )
+                              * dragPosition.x ) / ( (float) steps );
+            newPosition.y = ( screenPoint.y + ( (float) steps - 1.0 )
+                              * dragPosition.y) / ( (float) steps );
+            [self _moveDraggedImageToNewPosition];
+            steps--;
+        }
+
+        [NSEvent stopPeriodicEvents];
+    }
+
+    if( waitFlag )
+    {
+        [NSThread sleepUntilDate:
+            [NSDate dateWithTimeIntervalSinceNow: SLIDE_TIME_STEP * 2.0]];
+    }
+}
+
+/**
+*/
+- (HWND) _windowAcceptingDnDDescendentOf: (HWND) hWndParent
+                                  underX: (int) x
+                                       Y: (int) y
+{
+    //POINT p = GSScreenPointToMS( NSMakePoint( x, y ) );
+    //return ChildWindowFromPoint( hWndParent, p );
+    return (HWND) 0;
+}
+
+/**
+    Find a window under coordinates (x, y) accepting drag and drop:
+    -1  If the only window found is the one we are dragging
+    0   If there is no window that accepts drag and drop
+*/
+- (HWND) _windowAcceptingDnDUnderX: (int) x
+                                 Y: (int) y
+{
+    POINT p;
+    p.x = x;
+    p.y = y;
+    return WindowFromPoint( p );
+
+    //HWND hWndParent = WindowFromPoint( p );
+    //[self _xWindowAcceptingDnDDescendentOf: hWndParent underX: x Y: y ];
+    //return (HWND) 0;
+}
+
+/*
+    NSDraggingInfo protocol
+*/
+
+- (NSWindow*) draggingDestinationWindow
+{
+    return dragWindow;
+}
+
+- (NSPoint) draggingLocation
+{
+    return dragPoint;
+}
+
+- (NSPasteboard*) draggingPasteboard
+{
+    return dragPasteboard;
+}
+
+- (int) draggingSequenceNumber
+{
+    return dragSequence;
+}
+
+- (id) draggingSource
+{
+    return dragSource;
+}
+
+- (unsigned int) draggingSourceOperationMask
+{
+    // Mix in possible modifiers
+    return dragMask & operationMask;
+}
+
+- (NSImage*) draggedImage
+{
+    if( dragSource )
+    {
+        return [dragCell image];
+    }
+    else
+    {
+        return nil;
+    }
+}
+
+/**
+*/
+- (NSPoint) draggedImageLocation
+{
+    NSPoint loc;
+
+    if (dragSource)
+    {
+        NSSize size;
+
+        size = [[dragCell image] size];
+        loc = NSMakePoint( dragPoint.x - size.width / 2, dragPoint.y - size.height / 2 );
+    }
+    else
+    {
+        loc = dragPoint;
+    }
+    return loc;
+}
+
+/**
+*/
+- (void) slideDraggedImageTo: (NSPoint) point
+{
+    [self _slideDraggedImageTo: point
+                 numberOfSteps: SLIDE_NR_OF_STEPS
+                waitAfterSlide: YES];
+}
+
+@end
+
+@interface WIN32Server (DragAndDrop)
+
+- (void) _resetDragTypesForWindow: (NSWindow *)win;
+
+@end
+
+@implementation WIN32Server (DragAndDrop)
+
+/**
+*/
+- (void) _resetDragTypesForWindow: (NSWindow *)win
+{
+    // TODO: ...
+}
+
+/**
+    add allowed drag types to window
+*/
+- (BOOL) addDragTypes: (NSArray*)types toWindow: (NSWindow *)win
+{
+    BOOL did_add;
+    did_add = [super addDragTypes: types toWindow: win];
+
+    // TODO: Check if window device exists
+    [self _resetDragTypesForWindow: win];
+
+    return did_add;
+}
+
+/**
+    remove allowed drag types from window
+*/
+- (BOOL) removeDragTypes: (NSArray*)types fromWindow: (NSWindow *)win
+{
+    BOOL did_change;
+    did_change = [super removeDragTypes: types fromWindow: win];
+
+    // TODO: Check if window device exists
+    //[self _resetDragTypesForWindow: win];
+
+    return did_change;
+}
+
+@end
+
+/*
+    Additional implementation of NSWindow derived class
+    used for instancing the shared drag window in init
+*/
+
+@implementation WIN32RawWindow
+
+- (BOOL) canBecomeMainWindow
+{
+    return NO;
+}
+
+- (BOOL) canBecomeKeyWindow
+{
+    return NO;
+}
+
+- (void) _initDefaults
+{
+    [super _initDefaults];
+    [self setReleasedWhenClosed: NO];
+    [self setExcludedFromWindowsMenu: YES];
+}
+
+- (void) orderWindow: (NSWindowOrderingMode) place
+          relativeTo: (int)otherWin
+{
+    //XSetWindowAttributes winattrs;
+    //unsigned long valuemask;
+    //gswindow_device_t *window;
+
+    [super orderWindow: place relativeTo: otherWin];
+
+    //window = [XGServer _windowWithTag: _windowNum];
+    //valuemask = (CWSaveUnder|CWOverrideRedirect);
+    //winattrs.save_under = True;
+
+    /* Temporarily make this False? we don't handle it correctly (fedor) */
+    //winattrs.override_redirect = False;
+    //XChangeWindowAttributes (XDPY, window->ident, valuemask, &winattrs);
+    [self setLevel: NSPopUpMenuWindowLevel];
+}
+
+@end /* WIN32RawWindow */
diff -u -w -b -r -N ./Older/Source/win32/WIN32Server.m ./Newer/Source/win32/WIN32Server.m
--- ./Older/Source/win32/WIN32Server.m	Fri Apr  2 15:28:20 2004
+++ ./Newer/Source/win32/WIN32Server.m	Thu May  6 12:43:47 2004
@@ -43,6 +43,7 @@
 
 #include "win32/WIN32Server.h"
 #include "win32/WIN32Geometry.h"
+#include "win32/WIN32DragView.h"
 
 static void 
 validateWindow(HWND hwnd, RECT rect);
@@ -104,7 +105,6 @@
 }
 
 /**
-
 */
 - (id) initWithAttributes: (NSDictionary *)info
 {
@@ -134,21 +134,17 @@
   UnregisterClass("GNUstepWindowClass", hinstance);
 }
 
-/**
-
-*/
 - (void) dealloc
 {
   [self _destroyWin32Context];
   [super dealloc];
 }
 
-/** Returns an instance of a class which implements the NSDraggingInfo
-    protocol. */
 - (id <NSDraggingInfo>) dragInfo
 {
-  [self subclassResponsibility: _cmd];
-  return nil;
+    return [WIN32DragView sharedDragView];
+    //[self subclassResponsibility: _cmd];
+    //return nil;
 }
 
 - (BOOL) slideImage: (NSImage*)image from: (NSPoint)from to: (NSPoint)to
@@ -157,7 +153,9 @@
   return NO;
 }
 
-/* Screen information */
+/**
+    Screen information
+*/
 - (NSSize) resolutionForScreen: (int)screen
 {
   int xres, yres;
@@ -171,12 +169,18 @@
   return NSMakeSize(xres, yres);
 }
 
+/**
+    TODO: multiple monitors
+*/
 - (NSRect) boundsForScreen: (int)screen
 {
   return NSMakeRect(0, 0, GetSystemMetrics(SM_CXSCREEN), 
 		    GetSystemMetrics(SM_CYSCREEN));
 }
 
+/**
+    TODO: multiple monitors
+*/
 - (NSWindowDepth) windowDepthForScreen: (int)screen
 {
   HDC hdc;
@@ -192,6 +196,9 @@
   return (_GSRGBBitValue | bits);
 }
 
+/**
+    TODO: multiple monitors
+*/
 - (const NSWindowDepth *) availableDepthsForScreen: (int)screen
 {
   int		 ndepths = 1;
@@ -206,13 +213,17 @@
   return depths;
 }
 
+/**
+    TODO: multiple monitors if available
+*/
 - (NSArray *) screenList
 {
   return [NSArray arrayWithObject: [NSNumber numberWithInt: 0]];
 }
 
 /**
-   Returns the handle of the module instance.  */
+   Returns the handle of the module instance
+*/
 - (void *) serverDevice
 {
   return hinstance;
@@ -399,6 +410,8 @@
   DPSinitclip(ctxt);
 }
 
+/**
+*/
 - (void) orderwindow: (int) op : (int) otherWin : (int) winNum
 {
   NSDebugLLog(@"WTrace", @"orderwindow: %d : %d : %d", op, otherWin, winNum);
@@ -409,8 +422,7 @@
          - don't show the application icon window
 	 - Never order out the main menu, just minimize it, so that
 	 when the user clicks on it in the taskbar it will activate the
-	 application.
-      */
+           application. */
       int special;
       special = [[NSApp iconWindow] windowNumber];
       if (winNum == special)
@@ -431,7 +443,8 @@
       if (IsIconic((HWND)winNum))
         flag = SW_RESTORE;
       ShowWindow((HWND)winNum, flag); 
-      return;
+
+        //return;
     }
 
   switch (op)
@@ -440,36 +453,71 @@
       SetWindowPos((HWND)winNum, NULL, 0, 0, 0, 0, 
 		   SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER);
       break;
+
     case NSWindowBelow:
-      if (otherWin == 0)
+        NSDebugLLog( @"WTrace", @"orderwindow: NSWindowBelow: %d, %d",
+                     winNum, otherWin );
+        //if( otherWin == 0 )
+        if( otherWin <= 0 )
+        {
 	otherWin = (int)HWND_BOTTOM;
+        }
+        //else // TEMP!
+
       SetWindowPos((HWND)winNum, (HWND)otherWin, 0, 0, 0, 0, 
-		   SWP_NOSIZE | SWP_NOMOVE);
+                      SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
       break;
+
     case NSWindowAbove:
+        NSDebugLLog( @"WTrace", @"orderwindow: NSWindowAbove: %d, %d", winNum, otherWin );
       if (otherWin <= 0)
 	{
-	  /* FIXME: Need to find the current key window (otherWin == 0
-	     means keep the window below the current key.)  */
+            // FIXME: Need to find the current key window
+            // (otherWin == 0 means keep the window below the current key.)
 	  otherWin = winNum;
 	  winNum = (int)HWND_TOP;
 	}
+        //else // TEMP!
+
       SetWindowPos((HWND) otherWin, (HWND)winNum, 0, 0, 0, 0, 
-		   SWP_NOSIZE | SWP_NOMOVE);
+                      SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
       break;
     }
 }
 
+/**
+    Restrict the displayed part of the window to the given image.
+    This only yields usefull results if the window is borderless and
+    displays the image itself
+*/
+- (void) restrictWindow: (int) win toImage: (NSImage*) image
+{
+    if( win == 0 )
+    {
+        NSLog(@"Invalidparam: Restricting invalid window %d", win);
+        return;
+    }
+
+    // ...
+}
+
 - (void) movewindow: (NSPoint)loc : (int)winNum
 {
   POINT p;
 
   NSDebugLLog(@"WTrace", @"movewindow: %@ : %d", NSStringFromPoint(loc), 
 	      winNum);
+
   p = GSWindowOriginToMS((HWND)winNum, loc);
 
   SetWindowPos((HWND)winNum, NULL, p.x, p.y, 0, 0, 
-	       SWP_NOZORDER | SWP_NOSIZE | SWP_NOREDRAW);
+                  //SWP_NOZORDER | SWP_NOSIZE | SWP_NOREDRAW );
+                  SWP_NOZORDER | SWP_NOSIZE ); // ...
+    // ...
+    // ma.garcias
+    // redraw the window while moving
+    // handle WM_MOVED event just like the WM_SETFOCUS
+    // notifying the movement to the windows GUI and ignore the further message
 }
 
 - (void) placewindow: (NSRect)frame : (int) winNum
@@ -480,11 +528,16 @@
 
   NSDebugLLog(@"WTrace", @"placewindow: %@ : %d", NSStringFromRect(frame), 
 	      winNum);
+
   r = GSScreenRectToMS(frame);
   GetWindowRect((HWND)winNum, &r2);
 
+    NSDebugLLog( @"NSDragging", @"placewindow: %d, %d : %d", r.left, r.top,
+                 winNum );
+
   SetWindowPos((HWND)winNum, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, 
-	       SWP_NOZORDER | SWP_NOREDRAW);
+                  //SWP_NOZORDER | SWP_NOREDRAW );
+                  SWP_NOZORDER ); // ...
 
   if ((win->useHDC) &&
       (r.right - r.left != r2.right - r2.left) &&
@@ -613,7 +666,7 @@
 - (void) setinputfocus: (int) winNum
 {
   NSDebugLLog(@"WTrace", @"setinputfocus: %d", winNum);
-  NSDebugLLog(@"Focus", @"Setting input focus to %d");
+  NSDebugLLog(@"Focus", @"Setting input focus to %d", winNum);
   if (winNum == 0)
     {
       NSDebugLLog(@"Focus", @" invalid focus window");
diff -u -w -b -r -N ./Older/Source/win32/WIN32ServerEvent.m ./Newer/Source/win32/WIN32ServerEvent.m
--- ./Older/Source/win32/WIN32ServerEvent.m	Thu May  6 12:11:40 2004
+++ ./Newer/Source/win32/WIN32ServerEvent.m	Thu May  6 12:04:07 2004
@@ -62,6 +62,8 @@
 
 @interface WIN32Server (Internal)
 - (NSEvent *) handleGotFocus: (HWND)hwnd;
+- (NSEvent *) handleMoveSize: (HWND)hwnd //: (WPARAM)wParam : (LPARAM)lParam
+                            : (GSAppKitSubtype) subtype;
 - (LRESULT) windowEventProc: (HWND)hwnd : (UINT)uMsg 
 		       : (WPARAM)wParam : (LPARAM)lParam;
 @end
@@ -169,12 +171,62 @@
   return e;
 }
 
+/**
+*/
+- (NSEvent *) handleMoveSize: (HWND)hwnd //: (WPARAM)wParam : (LPARAM)lParam
+                            : (GSAppKitSubtype) subtype
+{
+    NSPoint eventLocation;
+    NSRect rect;
+    RECT r;
+    NSEvent *ev = nil;
+
+    GetWindowRect(hwnd, &r);
+    rect = MSScreenRectToGS(r);
+    eventLocation = rect.origin;
+
+    NSWindow *window = GSWindowWithNumber( (int) hwnd );
+    if( window )
+    {
+        if( subtype == GSAppKitWindowMoved )
+        {
+            ev = [NSEvent otherEventWithType: NSAppKitDefined
+                                    location: eventLocation
+                               modifierFlags: 0
+                                   timestamp: 0
+                                windowNumber: (int) hwnd
+                                     context: GSCurrentContext()
+                                     subtype: GSAppKitWindowMoved
+                                       data1: rect.origin.x
+                                       data2: rect.origin.y];
+        }
+        else if( subtype == GSAppKitWindowResized )
+        {
+            ev = [NSEvent otherEventWithType: NSAppKitDefined
+                                    location: eventLocation
+                               modifierFlags: 0
+                                   timestamp: 0
+                                windowNumber: (int) hwnd
+                                     context: GSCurrentContext()
+                                     subtype: GSAppKitWindowResized
+                                       data1: rect.size.width
+                                       data2: rect.size.height];
+        }
+        else
+        {
+            return nil;
+        }
+    }
+    return ev;
+}
+
+/**
+    main window message handling
+*/
 - (LRESULT) windowEventProc: (HWND)hwnd : (UINT)uMsg 
 		       : (WPARAM)wParam : (LPARAM)lParam
 { 
   NSEvent *ev = nil;
-  NSPoint eventLoc;
-
   switch (uMsg) 
     { 
     case WM_SETTEXT: 
@@ -280,18 +332,62 @@
     case WM_WINDOWPOSCHANGED: 
       NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "WINDOWPOSCHANGED", hwnd);
       break;
+
     case WM_MOVE:
-      eventLoc = MSWindowPointToGS(hwnd,  GET_X_LPARAM(lParam), 
-				   GET_Y_LPARAM(lParam));
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d to %@", "MOVE", hwnd,
-		  NSStringFromPoint(eventLoc));
+    {
+        NSDebugLLog( @"NSEvent", @"Got Message %s for %d", "SIZE", hwnd );
+        NSDebugLLog( @"Moving", @"Got Message %s for %d (%d, %d)", "MOVE", hwnd,
+                     (short) GET_X_LPARAM(lParam), (short) GET_Y_LPARAM(lParam) );
+
+        /* These messages come when the window has already been moved or resized,
+           so we send the event to the frontend window directly instead of the app
+           which could get the window state out of sync */
+        NSWindow *window = GSWindowWithNumber( (int) hwnd );
+        if( window )
+        {
+            ev = [self handleMoveSize: hwnd : GSAppKitWindowMoved];
+            if (ev != nil)
+            {
+                [window sendEvent: ev];
+            }
+        }
+        ev = nil;
       break;
+    }
     case WM_MOVING: 
       NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MOVING", hwnd);
       break;
+
     case WM_SIZE: 
+    {
+        NSString *wParamString;
+        switch( wParam )
+        {
+            case SIZE_MAXHIDE:   wParamString = @"SIZE_MAXHIDE"; break;
+            case SIZE_MAXIMIZED: wParamString = @"SIZE_MAXIMIZED"; break;
+            case SIZE_MAXSHOW:   wParamString = @"SIZE_MAXSHOW"; break;
+            case SIZE_MINIMIZED: wParamString = @"SIZE_MINIMIZED"; break;
+            case SIZE_RESTORED:  wParamString = @"SIZE_RESTORED"; break;
+            default: wParamString = @"";
+        }
       NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "SIZE", hwnd);
+        NSDebugLLog( @"Sizing", @"Got Message %s for %d (%d, %d) %@", "SIZE", hwnd,
+                     (short) GET_X_LPARAM(lParam), (short) GET_Y_LPARAM(lParam),
+                     wParamString );
+
+        // same as in WM_MOVE
+        NSWindow *window = GSWindowWithNumber( (int) hwnd );
+        if( window )
+        {
+            ev = [self handleMoveSize: hwnd : GSAppKitWindowResized];
+            if (ev != nil)
+            {
+                [window sendEvent: ev];
+            }
+        }
+        ev = nil;
       break;
+    }
     case WM_SIZING: 
       NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "SIZING", hwnd);
       break;
@@ -300,12 +396,12 @@
       break;
     case WM_EXITSIZEMOVE: 
       {
-	NSPoint eventLocation;
-	NSRect rect;
+        //NSPoint eventLocation;
+        //NSRect rect;
 	RECT r;
 	WIN_INTERN *win = (WIN_INTERN *)GetWindowLong((HWND)hwnd, GWL_USERDATA);
 	
-	// FIXME: We should check if the size really did change.
+        // @FIXME: We should check if the size really did change.
 	if (win->useHDC)
 	  {
 	    HDC hdc, hdc2;
@@ -328,11 +424,13 @@
 	    
 	    ReleaseDC((HWND)hwnd, hdc);
 	  }
+        NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "EXITSIZEMOVE", hwnd);
+        ev = [self handleMoveSize: hwnd : GSAppKitWindowResized];
 
-	GetWindowRect(hwnd, &r);
+        /*GetWindowRect(hwnd, &r);
 	rect = MSScreenRectToGS(r);
 	eventLocation = rect.origin;
-	NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "EXITSIZEMOVE", hwnd);
+
 	ev = [NSEvent otherEventWithType: NSAppKitDefined
 		      location: eventLocation
 		      modifierFlags: 0
@@ -341,12 +439,13 @@
 		      context: GSCurrentContext()
 		      subtype: GSAppKitWindowResized
 		      data1: rect.size.width
-		      data2: rect.size.height];
+                                   data2: rect.size.height];*/
 	if (ev != nil)
 	  {
 	    [GSCurrentServer() postEvent: ev atStart: NO];
 	  }
-	ev = [NSEvent otherEventWithType: NSAppKitDefined
+        ev = [self handleMoveSize: hwnd : GSAppKitWindowMoved];
+        /*ev = [NSEvent otherEventWithType: NSAppKitDefined
 		      location: eventLocation
 		      modifierFlags: 0
 		      timestamp: 0
@@ -354,15 +453,15 @@
 		      context: GSCurrentContext()
 		      subtype: GSAppKitWindowMoved
 		      data1: rect.origin.x
-		      data2: rect.origin.y];
+                                     data2: rect.origin.y];*/
 	if (ev != nil)
 	  {
 	    [GSCurrentServer() postEvent: ev atStart: NO];
 	  }
-	// Make sure DefWindowProc gets called
-	ev = nil;
+        ev = nil; // Make sure DefWindowProc gets called
 	break;
       }
+
     case WM_ACTIVATE: 
       NSDebugLLog(@"NSEvent", @"Got Message %s for %d: %s %d", "ACTIVATE", 
 		  hwnd, (LOWORD(wParam)) ? "activate" : "deactivate",
@@ -370,6 +469,7 @@
       if (LOWORD(wParam))
 	currentActive = hwnd;
       break;
+
     case WM_ACTIVATEAPP:
       {
 	int special;
@@ -436,11 +536,17 @@
 
 	if (GetUpdateRect(hwnd, &rect, NO))
 	  {
+            NSDebugLLog(@"NSEvent", @"Got Message %s for %d with rect = ", "PAINT", hwnd );
 	    invalidateWindow(hwnd, rect);
-	    ValidateRect(hwnd, &rect);
+            // validate the whole window, for in some cases an infinite series
+            // of WM_PAINT is triggered
+            //ValidateRect(hwnd, &rect);
+            ValidateRect( hwnd, NULL );
 	  }
-
+        else
+        {
 	NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "PAINT", hwnd);
+        }
 	return 0;
       }
     case WM_SYNCPAINT: 
@@ -491,44 +597,44 @@
       break;
 
     case WM_MOUSEMOVE: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MOUSEMOVE", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "MOUSEMOVE", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSMouseMoved);
       break;
     case WM_LBUTTONDOWN: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "LBUTTONDOWN", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "LBUTTONDOWN", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSLeftMouseDown);
       break;
     case WM_LBUTTONUP: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "LBUTTONUP", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "LBUTTONUP", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSLeftMouseUp);
       break;
     case WM_LBUTTONDBLCLK: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "LBUTTONDBLCLK", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "LBUTTONDBLCLK", hwnd);
       break;
     case WM_MBUTTONDOWN: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MBUTTONDOWN", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "MBUTTONDOWN", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSOtherMouseDown);
       break;
     case WM_MBUTTONUP: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MBUTTONUP", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "MBUTTONUP", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSOtherMouseUp);
       break;
     case WM_MBUTTONDBLCLK: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MBUTTONDBLCLK", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "MBUTTONDBLCLK", hwnd);
       break;
     case WM_RBUTTONDOWN: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "RBUTTONDOWN", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "RBUTTONDOWN", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSRightMouseDown);
       break;
     case WM_RBUTTONUP: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "RBUTTONUP", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "RBUTTONUP", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSRightMouseUp);
       break;
     case WM_RBUTTONDBLCLK: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "RBUTTONDBLCLK", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "RBUTTONDBLCLK", hwnd);
       break;
     case WM_MOUSEWHEEL: 
-      NSDebugLLog(@"NSEvent", @"Got Message %s for %d", "MOUSEWHEEL", hwnd);
+      NSDebugLLog(@"NSMouseEvent", @"Got Message %s for %d", "MOUSEWHEEL", hwnd);
       ev = process_mouse_event(hwnd, wParam, lParam, NSScrollWheel);
       break;
 
@@ -784,6 +890,15 @@
   return event;
 }
 
+
+
+/**
+    process mouse event
+    fills up the NSEvent structure for a mouse event
+    converts NSMouseMove events to NS*MouseDragged for pressed keys
+    convert wheel movement to wheel delta
+    handle multiple clicks (there is no double click event)
+*/
 static NSEvent*
 process_mouse_event(HWND hwnd, WPARAM wParam, LPARAM lParam, 
 		    NSEventType eventType)
@@ -800,12 +915,18 @@
   static LONG lastTime = 0;
 
   gcontext = GSCurrentContext();
-  eventLocation = MSWindowPointToGS(hwnd,  GET_X_LPARAM(lParam), 
-				    GET_Y_LPARAM(lParam));
+
+    //NSDebugLLog( @"NSDragging", @"process_mouse_event %d, %d", (short) GET_X_LPARAM(lParam),
+    //                                                           (short) GET_Y_LPARAM(lParam) );
+
+  eventLocation = MSWindowPointToGS( hwnd,
+                                     (short) GET_X_LPARAM(lParam),
+                                     (short) GET_Y_LPARAM(lParam) );
   ltime = GetMessageTime();
   time = ltime / 1000;
   tick = GetTickCount();
   eventFlags = 0;
+
   if (wParam & MK_CONTROL)
     {
       eventFlags |= NSControlKeyMask;
@@ -823,7 +944,7 @@
   if (eventType == NSScrollWheel)
     {
       deltaY = GET_WHEEL_DELTA_WPARAM(wParam) / 120;
-      //NSLog(@"Scroll event with delat %d", deltaY);
+      //NSLog(@"Scroll event with delta %d", deltaY);
     }
   else if (eventType == NSMouseMoved)
     {
@@ -872,6 +993,9 @@
   return event;
 }
 
+/**
+    (description forthcoming)
+*/
 static void 
 invalidateWindow(HWND hwnd, RECT rect)
 {
@@ -898,10 +1022,10 @@
       NSWindow *window = GSWindowWithNumber((int)hwnd);
       NSRect r = MSWindowRectToGS((HWND)hwnd, rect);
       
-      /*
-	NSLog(@"Invalidated window %d %@ (%d, %d, %d, %d)", hwnd, 
-	NSStringFromRect(r), rect.left, rect.top, rect.right, rect.bottom);
-      */
+        NSDebugLLog( @"NSEvent", @"Invalidated window %d %@ (%d, %d, %d, %d)",
+                     hwnd, NSStringFromRect(r),
+                     rect.left, rect.top, rect.right, rect.bottom );
+
       // Repaint the window's client area. 
       [[window contentView] setNeedsDisplayInRect: r];
     }
diff -u -w -b -r -N ./Older/Source/win32/subproject.def ./Newer/Source/win32/subproject.def
--- ./Older/Source/win32/subproject.def	Thu Jan  1 01:00:00 1970
+++ ./Newer/Source/win32/subproject.def	Tue May  4 16:11:34 2004
@@ -0,0 +1,2 @@
+; C:\GNUstep\Development\mingw\bin\dlltool.exe --output-def subproject.def ./shared_obj/WIN32Server.o ./shared_obj/WIN32DragView.o ./shared_obj/WIN32ServerEvent.o
+EXPORTS
