Window frame/coordinate handling cleanups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@23461 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2006-09-12 09:50:14 +00:00
parent e11c20b9ed
commit c1cdc25750
13 changed files with 148 additions and 94 deletions

View file

@ -158,6 +158,11 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
return 0;
}
@interface XGServer (WindowOps)
- (void) styleoffsets: (float *) l : (float *) r : (float *) t : (float *) b
: (unsigned int) style : (Window) win;
@end
@implementation XGServer (EventOps)
- (int) XGErrorHandler: (Display*)display : (XErrorEvent*)err
@ -296,6 +301,25 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
}
}
/*
*/
- (NSPoint) _XPointToOSPoint: (NSPoint)x for: (void*)window
{
gswindow_device_t *win = (gswindow_device_t*)window;
unsigned int style = win->win_attrs.window_style;
NSPoint o;
float t, b, l, r;
[self styleoffsets: &l : &r : &t : &b : style : win->ident];
o.x = x.x + l;
o.y = NSHeight(win->xframe) - x.y + b;
NSDebugLLog(@"Frame", @"X2OP %d, %x, %@, %@", win->number, style,
NSStringFromPoint(x), NSStringFromPoint(o));
return o;
}
- (void) processEvent: (XEvent *) event
{
static int clickCount = 1;
@ -322,21 +346,21 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
xEvent.xbutton.window, xEvent.xbutton.time,
generic.lastClick);
/*
* hardwired test for a double click
*
* For multiple clicks, the clicks must remain in the same
* region of the same window and must occur in a limited time.
*
* default time of 300 should be user set;
* perhaps the movement of 3 should also be a preference?
*/
* hardwired test for a double click
*
* For multiple clicks, the clicks must remain in the same
* region of the same window and must occur in a limited time.
*
* default time of 300 should be user set;
* perhaps the movement of 3 should also be a preference?
*/
{
BOOL incrementCount = YES;
#define CLICK_TIME 300
#define CLICK_MOVE 3
#define CLICK_TIME 300
#define CLICK_MOVE 3
if (xEvent.xbutton.time
>= (unsigned long)(generic.lastClick + CLICK_TIME))
>= (unsigned long)(generic.lastClick + CLICK_TIME))
incrementCount = NO;
else if (generic.lastClickWindow != xEvent.xbutton.window)
incrementCount = NO;
@ -385,7 +409,7 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
eventType = NSScrollWheel;
}
else if (xEvent.xbutton.button == generic.downMouse
&& generic.downMouse != 0)
&& generic.downMouse != 0)
{
deltaY = -1.;
eventType = NSScrollWheel;
@ -403,7 +427,9 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
if (cWin == 0)
break;
eventLocation.x = xEvent.xbutton.x;
eventLocation.y = NSHeight(cWin->xframe)-xEvent.xbutton.y;
eventLocation.y = xEvent.xbutton.y;
eventLocation = [self _XPointToOSPoint: eventLocation
for: cWin];
if (generic.flags.useWindowMakerIcons == 1)
{
@ -468,7 +494,9 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
if (cWin == 0)
break;
eventLocation.x = xEvent.xbutton.x;
eventLocation.y = NSHeight(cWin->xframe)-xEvent.xbutton.y;
eventLocation.y = xEvent.xbutton.y;
eventLocation = [self _XPointToOSPoint: eventLocation
for: cWin];
e = [NSEvent mouseEventWithType: eventType
location: eventLocation
@ -609,8 +637,8 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
NSMinX(cWin->xframe);
eventLocation.y = XDND_POSITION_ROOT_Y(&xEvent) -
NSMinY(cWin->xframe);
eventLocation.y = NSHeight(cWin->xframe) -
eventLocation.y;
eventLocation = [self _XPointToOSPoint: eventLocation
for: cWin];
time = XDND_POSITION_TIME(&xEvent);
action = XDND_POSITION_ACTION(&xEvent);
operation = GSDragOperationForAction(action);
@ -1218,8 +1246,9 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
deltaX = - eventLocation.x;
deltaY = - eventLocation.y;
eventLocation = NSMakePoint(xEvent.xmotion.x,
NSHeight(cWin->xframe) - xEvent.xmotion.y);
eventLocation = NSMakePoint(xEvent.xmotion.x, xEvent.xmotion.y);
eventLocation = [self _XPointToOSPoint: eventLocation
for: cWin];
deltaX += eventLocation.x;
deltaY += eventLocation.y;
@ -1626,14 +1655,12 @@ process_key_event (XEvent* xEvent, XGServer* context, NSEventType eventType)
/* Process location */
window = [XGServer _windowWithTag: [[NSApp keyWindow] windowNumber]];
eventLocation.x = xEvent->xbutton.x;
if (window)
{
eventLocation.y = window->siz_hints.height - xEvent->xbutton.y;
}
else
if (window != 0)
{
eventLocation.x = xEvent->xbutton.x;
eventLocation.y = xEvent->xbutton.y;
eventLocation = [context _XPointToOSPoint: eventLocation
for: window];
}
/* Process characters */

View file

@ -450,19 +450,22 @@ static void setWindowHintsForStyle (Display *dpy, Window window,
/*
* Convert a rectangle in X coordinates relative to the X-window
* to a rectangle in OpenStep coordinates in the topmost view in the
* NSWindow.
* to a rectangle in OpenStep coordinates (base coordinates of the NSWindow).
*/
- (NSRect) _XWinRectToOSViewRect: (NSRect)x for: (void*)window
- (NSRect) _XWinRectToOSWinRect: (NSRect)x for: (void*)window
{
gswindow_device_t *win = (gswindow_device_t*)window;
unsigned int style = win->win_attrs.window_style;
NSRect o;
float t, b, l, r;
[self styleoffsets: &l : &r : &t : &b : style : win->ident];
o.size.width = x.size.width;
o.size.height = x.size.height;
o.origin.x = x.origin.x;
o.origin.y = win->siz_hints.height - x.origin.y;
o.origin.y = o.origin.y - o.size.height;
NSDebugLLog(@"Frame", @"XW2OV %@ %@",
o.origin.x = x.origin.x - l;
o.origin.y = NSHeight(win->xframe) - x.origin.y;
o.origin.y = o.origin.y - x.size.height - b;
NSDebugLLog(@"Frame", @"XW2OW %@ %@",
NSStringFromRect(x), NSStringFromRect(o));
return o;
}
@ -1847,6 +1850,7 @@ static void setWindowHintsForStyle (Display *dpy, Window window,
unsigned width, height;
gswindow_device_t *window;
NSGraphicsContext *ctxt;
float t, b, l, r;
NSDebugLLog(@"XGTrace", @"DPSwindowdevice: %d ", win);
window = WINDOW_WITH_TAG(win);
@ -1863,8 +1867,8 @@ static void setWindowHintsForStyle (Display *dpy, Window window,
height = NSHeight(window->xframe);
if (window->buffer
&& (window->buffer_width != width || window->buffer_height != height)
&& (window->gdriverProtocol & GDriverHandlesBacking) == 0)
&& (window->buffer_width != width || window->buffer_height != height)
&& (window->gdriverProtocol & GDriverHandlesBacking) == 0)
{
[isa waitAllContexts];
XFreePixmap(dpy, window->buffer);
@ -1883,8 +1887,11 @@ static void setWindowHintsForStyle (Display *dpy, Window window,
}
ctxt = GSCurrentContext();
GSSetDevice(ctxt, window, 0, NSHeight(window->xframe));
[self styleoffsets: &l : &r : &t : &b
: window->win_attrs.window_style : window->ident];
GSSetDevice(ctxt, window, l, NSHeight(window->xframe) + b);
DPSinitmatrix(ctxt);
//DPStranslate(ctxt, -l, -b);
DPSinitclip(ctxt);
}
@ -2638,7 +2645,7 @@ static BOOL didCreatePixmaps;
// Transform the rectangle's coordinates to OS coordinates and add
// this new rectangle to the list of exposed rectangles.
{
rect = [self _XWinRectToOSViewRect: NSMakeRect(
rect = [self _XWinRectToOSWinRect: NSMakeRect(
rectangle.x, rectangle.y, rectangle.width, rectangle.height)
for: window];
[window->exposedRects addObject: [NSValue valueWithRect: rect]];
@ -2738,7 +2745,7 @@ static BOOL didCreatePixmaps;
NSValue *val[n];
int i;
v = [gui_win _windowView];
v = [[gui_win contentView] superview];
[window->exposedRects getObjects: val];
for (i = 0; i < n; ++i)