From d2dcf1935668b3f4fe5861058e65b98751f1ceb2 Mon Sep 17 00:00:00 2001 From: Fred Kiefer Date: Wed, 3 May 2006 21:09:08 +0000 Subject: [PATCH] Allow wrapping of native windows into NSWindow. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@22851 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++ .../Additions/GNUstepGUI/GSDisplayServer.h | 2 + Source/GSDisplayServer.m | 9 +++ Source/NSWindow.m | 60 +++++++++++++++---- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c9bcabde..f455ecd5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-05-03 Fred Kiefer + + * Headers/Additions/GNUstepGUI/GSDisplayServer.h (-nativeWindow:::::): + Added new method. + * Source/GSDisplayServer.m (-nativeWindow:::::): + Implemented this method as subclassResponsibility. + * Source/NSWindow.m (-initWithWindowRef:], -windowRef): + Implemented these methods to wrap native window into GNUstep windows. + 2006-05-01 Richard Frith-Macdonald * Source/NSMatrix..m: ([performKeyEquivalent:]) Check modifier flags diff --git a/Headers/Additions/GNUstepGUI/GSDisplayServer.h b/Headers/Additions/GNUstepGUI/GSDisplayServer.h index 998d2ef77..102d2da55 100644 --- a/Headers/Additions/GNUstepGUI/GSDisplayServer.h +++ b/Headers/Additions/GNUstepGUI/GSDisplayServer.h @@ -116,6 +116,8 @@ APPKIT_EXPORT NSString * GSScreenNumber; - (int) window: (NSRect)frame : (NSBackingStoreType)type : (unsigned int)style : (int)screen; - (void) termwindow: (int) win; +- (int) nativeWindow: (void *)winref : (NSRect*)frame : (NSBackingStoreType*)type + : (unsigned int*)style : (int*)screen; /* Only if handlesWindowDecorations returns YES. */ - (void) stylewindow: (unsigned int) style : (int) win; diff --git a/Source/GSDisplayServer.m b/Source/GSDisplayServer.m index d425b53dc..b59f656e5 100644 --- a/Source/GSDisplayServer.m +++ b/Source/GSDisplayServer.m @@ -547,6 +547,15 @@ GSCurrentServer(void) [self subclassResponsibility: _cmd]; } +/** Create all the backend structures for a reference to a native window and + return the extend, backing type, style and screen for that window. */ +- (int) nativeWindow: (void *)winref : (NSRect*)frame : (NSBackingStoreType*)type + : (unsigned int*)style : (int*)screen +{ + [self subclassResponsibility: _cmd]; + return 0; +} + /** Sets the style of the window. See [NSWindow-styleMask] for a description of the available styles */ - (void) stylewindow: (unsigned int) style : (int) win diff --git a/Source/NSWindow.m b/Source/NSWindow.m index f989ada74..d6ae9328a 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -984,6 +984,51 @@ many times. return self; } +- (id) initWithWindowRef: (void *)windowRef +{ + NSRect contentRect; + unsigned int aStyle; + NSBackingStoreType bufferingType; + NSScreen* aScreen; + int screen; + int winNum; + NSGraphicsContext *context = GSCurrentContext(); + GSDisplayServer *srv = GSCurrentServer(); + + // Get the properties for the underlying window + winNum = [srv nativeWindow: windowRef : &contentRect : &bufferingType + : &aStyle : &screen]; + // FIXME: Get the screen for the right screen number. + aScreen = nil; + + // Set up a NSWindow with the same properties + self = [self initWithContentRect: contentRect + styleMask: aStyle + backing: bufferingType + defer: YES + screen: aScreen]; + + // Fake the initialisation of the backend + _windowNum = winNum; + NSMapInsert (windowmaps, (void*)(intptr_t)_windowNum, self); + + // Set window in new _gstate + DPSgsave(context); + [srv windowdevice: _windowNum]; + _gstate = GSDefineGState(context); + DPSgrestore(context); + + { + NSRect frame = _frame; + frame.origin = NSZeroPoint; + [_wv setFrame: frame]; + [_wv setNeedsDisplay: YES]; + [_wv setWindowNumber: _windowNum]; + } + + return self; +} + -(void) colorListChanged:(NSNotification*)notif { if ([[notif object] isEqual: [NSColorList colorListNamed:@"System"]]) @@ -4222,20 +4267,11 @@ resetCursorRectsForView(NSView *theView) return nil; } -- (id) initWithWindowRef: (void *)windowRef -{ - // TODO - NSLog(@"Method %s is not implemented for class %s", - "initWithWindowRef:", "NSWindow"); - return nil; -} - - (void *)windowRef { - // TODO - NSLog(@"Method %s is not implemented for class %s", - "windowRef", "NSWindow"); - return (void *) 0; + GSDisplayServer *srv = GSServerForWindow(self); + + return [srv windowDevice: _windowNum]; } - (void *) windowHandle