Implement NSApplication's -context method.

Add global variable to NSApplication to prevent -release loops when
it is being dealloced.
Remove debugging information.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@1634 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
gnustep 1996-06-06 13:55:06 +00:00
parent ec1a865b4b
commit f5813d015b
6 changed files with 48 additions and 48 deletions

View file

@ -1,3 +1,16 @@
Thu Jun 6 09:20:51 1996 GNUstep Development <gnustep@duncan.ocbi.com>
* Headers/gnustep/gui/NSApplication.h (-context): New method.
* Source/Makefile.sed.nt (install): Delete AppKit and DPSClient
headers directories before installing headers.
* Source/NSApplication.m (gnustep_gui_app_is_in_dealloc): New
global variable to flag when the application is being dealloced
so it can prevent -release loops.
(+initialize, -dealloc, -removeWindowsItem:): Likewise.
(-context): New method.
* Source/NSView.m (+pushFocusView, +focusView): Remove
debugging information.
Mon Jun 3 10:54:28 1996 GNUstep Development <gnustep@duncan.ocbi.com> Mon Jun 3 10:54:28 1996 GNUstep Development <gnustep@duncan.ocbi.com>
* Makefile.in (clean-top, distclean): Correct targets and clean * Makefile.in (clean-top, distclean): Correct targets and clean

View file

@ -41,6 +41,7 @@
#include <Foundation/NSDate.h> #include <Foundation/NSDate.h>
#include <gnustep/base/Queue.h> #include <gnustep/base/Queue.h>
#include <Foundation/NSCoder.h> #include <Foundation/NSCoder.h>
#include <DPSClient/NSDPSContext.h>
@interface NSApplication : NSResponder <NSCoding> @interface NSApplication : NSResponder <NSCoding>
@ -196,7 +197,7 @@
// //
// Getting the display postscript context // Getting the display postscript context
// //
// - (NSDOSContext *)context; - (NSDPSContext *)context;
// //
// Reporting an exception // Reporting an exception

View file

@ -54,7 +54,9 @@ install-headers:\
for %i in ( $(GNUSTEP_DPS_HEADERS) ) do \\\ for %i in ( $(GNUSTEP_DPS_HEADERS) ) do \\\
( $(INSTALL_DATA) ../Headers/gnustep/%i \\\ ( $(INSTALL_DATA) ../Headers/gnustep/%i \\\
$(includedir)/gnustep/%i ) \ $(includedir)/gnustep/%i ) \
IF EXIST $(includedir)\\AppKit rm -rf $(includedir)/AppKit \
cp -r $(includedir)/gnustep/gui $(includedir)/AppKit \ cp -r $(includedir)/gnustep/gui $(includedir)/AppKit \
IF EXIST $(includedir)\\DPSClient rm -rf $(includedir)/DPSClient \
cp -r $(includedir)/gnustep/dps $(includedir)/DPSClient \ cp -r $(includedir)/gnustep/dps $(includedir)/DPSClient \
# end of install targets # end of install targets

View file

@ -39,6 +39,7 @@
// The global application instance // The global application instance
extern id NSApp; extern id NSApp;
NSEvent *NullEvent; NSEvent *NullEvent;
BOOL gnustep_gui_app_is_in_dealloc;
// Global strings // Global strings
NSString *NSModalPanelRunLoopMode = @"ModalPanelMode"; NSString *NSModalPanelRunLoopMode = @"ModalPanelMode";
@ -111,6 +112,10 @@ NSString *NSApplicationWillUpdateNotification;
// Initial version // Initial version
[self setVersion:1]; [self setVersion:1];
// So the application knows its within dealloc
// and can prevent -release loops.
gnustep_gui_app_is_in_dealloc = NO;
} }
} }
@ -154,9 +159,6 @@ NSString *NSApplicationWillUpdateNotification;
// //
[self setNextResponder:NULL]; [self setNextResponder:NULL];
// Finish the Launching
[self finishLaunching];
return self; return self;
} }
@ -177,15 +179,18 @@ NSString *NSApplicationWillUpdateNotification;
//NSLog(@"Freeing NSApplication\n"); //NSLog(@"Freeing NSApplication\n");
// Let ourselves know we are within dealloc
gnustep_gui_app_is_in_dealloc = YES;
// Release the window list // Release the window list
// We retain all of the objects in our list // We retain all of the objects in our list
// so we need to release them // so we need to release them
//NSArray doesn't know -removeAllObjects yet //NSArray doesn't know -removeAllObjects yet
//[window_list removeAllObjects]; [window_list removeAllObjects];
j = [window_list count]; //j = [window_list count];
for (i = 0;i < j; ++i) //for (i = 0;i < j; ++i)
[[window_list objectAtIndex:i] release]; // [[window_list objectAtIndex:i] release];
// no need -array is autoreleased // no need -array is autoreleased
//[window_list release]; //[window_list release];
@ -713,10 +718,7 @@ NSString *NSApplicationWillUpdateNotification;
if (![aWindow isKindOfClass:[NSWindow class]]) if (![aWindow isKindOfClass:[NSWindow class]])
return; return;
// Retain the window // Add to our window list, the array retains it
//[aWindow retain];
// Add to our window list
i = [window_list count]; i = [window_list count];
[window_list addObject:aWindow]; [window_list addObject:aWindow];
@ -748,26 +750,21 @@ NSString *NSApplicationWillUpdateNotification;
int i, j; int i, j;
id w; id w;
// This should be different // +++ This should be different
if (aWindow == key_window) if (aWindow == key_window)
key_window = nil; key_window = nil;
if (aWindow == main_window) if (aWindow == main_window)
main_window = nil; main_window = nil;
// Simple -find it and remove it // If we are within our dealloc then don't remove the window
j = [window_list count]; // Most likely dealloc is removing windows from our window list
for (i = 0;i < j; ++i) // and subsequently NSWindow is caling us to remove itself.
{ if (gnustep_gui_app_is_in_dealloc)
w = [window_list objectAtIndex:i];
if (w == aWindow)
{
// Remove from out list
[window_list removeObjectAtIndex:i];
// Release it because we retained it before
//[w release];
return; return;
}
} // Remove it from the window list
[window_list removeObject: aWindow];
return; return;
} }
@ -810,7 +807,10 @@ NSString *NSApplicationWillUpdateNotification;
} }
// Getting the display postscript context // Getting the display postscript context
// - (NSDOSContext *)context; - (NSDPSContext *)context
{
return [NSDPSContext currentContext];
}
// Reporting an exception // Reporting an exception
//- (void)reportException:(NSException *)anException //- (void)reportException:(NSException *)anException

View file

@ -140,7 +140,7 @@ BOOL GNU_CONTEXT_SYNCHRONIZED;
NSLog(@"NSDPSContext: +currentContext\n"); NSLog(@"NSDPSContext: +currentContext\n");
// Get current context for current thread // Get current context for current thread
[GNU_CONTEXT_LOCK lock]; [GNU_CONTEXT_LOCK lock];
NSLog(@"NSDPSContext: enter critical section\n");
current_context = [GNU_CONTEXT_THREAD_DICT objectForKey: current_thread]; current_context = [GNU_CONTEXT_THREAD_DICT objectForKey: current_thread];
NSLog(@"NSDPSContext: Looked in context dictionary\n"); NSLog(@"NSDPSContext: Looked in context dictionary\n");
@ -170,12 +170,10 @@ BOOL GNU_CONTEXT_SYNCHRONIZED;
// If no context then remove from dictionary // If no context then remove from dictionary
if (!context) if (!context)
{ {
NSLog(@"NSDPSContext: remove from dictionary\n");
[GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread]; [GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread];
} }
else else
{ {
NSLog(@"NSDPSContext: add to dictionary\n");
[GNU_CONTEXT_THREAD_DICT setObject: context [GNU_CONTEXT_THREAD_DICT setObject: context
forKey: current_thread]; forKey: current_thread];
} }

View file

@ -79,26 +79,21 @@ NSString *NSViewFocusChangedNotification;
{ {
NSThread *current_thread = [NSThread currentThread]; NSThread *current_thread = [NSThread currentThread];
NSLog(@"NSView: +pushFocusView\n"); // Obtain lock so we can edit the dictionary
[gnustep_gui_nsview_lock lock]; [gnustep_gui_nsview_lock lock];
NSLog(@"NSView: enter critical section\n");
// If no context then remove from dictionary // If no context then remove from dictionary
if (!focusView) if (!focusView)
{ {
NSLog(@"NSView: remove from dictionary\n");
[gnustep_gui_nsview_thread_dict removeObjectForKey: current_thread]; [gnustep_gui_nsview_thread_dict removeObjectForKey: current_thread];
} }
else else
{ {
NSLog(@"NSView: add to dictionary\n");
[gnustep_gui_nsview_thread_dict setObject: focusView [gnustep_gui_nsview_thread_dict setObject: focusView
forKey: current_thread]; forKey: current_thread];
} }
[gnustep_gui_nsview_lock unlock]; [gnustep_gui_nsview_lock unlock];
NSLog(@"NSView: exit critical section\n");
NSLog(@"NSView: return from +pushFocusView\n");
} }
+ (NSView *)popFocusView + (NSView *)popFocusView
@ -109,23 +104,14 @@ NSString *NSViewFocusChangedNotification;
NSThread *current_thread = [NSThread currentThread]; NSThread *current_thread = [NSThread currentThread];
NSView *current_view = nil; NSView *current_view = nil;
NSLog(@"NSView: +focusView\n");
// Get focused view for current thread // Get focused view for current thread
[gnustep_gui_nsview_lock lock]; [gnustep_gui_nsview_lock lock];
NSLog(@"NSView: enter critical section\n");
current_view = [gnustep_gui_nsview_thread_dict objectForKey: current_thread];
NSLog(@"NSView: Looked in view dictionary\n");
// If not in dictionary then no focused view // current_view is nil if no focused view
if (!current_view) current_view = [gnustep_gui_nsview_thread_dict objectForKey: current_thread];
NSLog(@"NSView: Did not find a view\n");
else
NSLog(@"NSView: Found a view\n");
[gnustep_gui_nsview_lock unlock]; [gnustep_gui_nsview_lock unlock];
NSLog(@"NSView: exit critical section\n");
NSLog(@"NSView: return from +focusView\n");
return current_view; return current_view;
} }