diff --git a/Source/Makefile.in b/Source/Makefile.in index 22d27bd6c..9ef0b55d6 100644 --- a/Source/Makefile.in +++ b/Source/Makefile.in @@ -312,6 +312,7 @@ clean: rm -f *~ rm -f *$(oext) rm -f $(MAIN_FILE)$(libext) + rm -f $(INIT_FILE).c distclean: clean rm -f Makefile maintainer-clean: distclean diff --git a/Source/NSDPSContext.m b/Source/NSDPSContext.m index 6c8427c77..1b6ccefeb 100644 --- a/Source/NSDPSContext.m +++ b/Source/NSDPSContext.m @@ -135,20 +135,27 @@ BOOL GNU_CONTEXT_SYNCHRONIZED; + (NSDPSContext *)currentContext { NSThread *current_thread = [NSThread currentThread]; - NSDPSContext *current_context; + NSDPSContext *current_context = nil; + NSLog(@"NSDPSContext: +currentContext\n"); // Get current context for current thread [GNU_CONTEXT_LOCK lock]; + NSLog(@"NSDPSContext: enter critical section\n"); current_context = [GNU_CONTEXT_THREAD_DICT objectForKey: current_thread]; + NSLog(@"NSDPSContext: Looked in context dictionary\n"); // If not in dictionary then create one if (!current_context) { + NSLog(@"NSDPSContext: Did not find context so create it\n"); current_context = [[NSDPSContext alloc] init]; + NSLog(@"NSDPSContext: set the context\n"); [self setCurrentContext: current_context]; } [GNU_CONTEXT_LOCK unlock]; + NSLog(@"NSDPSContext: exit critical section\n"); + NSLog(@"NSDPSContext: return from +currentContext\n"); return current_context; } @@ -156,16 +163,26 @@ BOOL GNU_CONTEXT_SYNCHRONIZED; { NSThread *current_thread = [NSThread currentThread]; + NSLog(@"NSDPSContext: +setCurrentContext\n"); [GNU_CONTEXT_LOCK lock]; + NSLog(@"NSDPSContext: enter critical section\n"); // If no context then remove from dictionary if (!context) - [GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread]; + { + NSLog(@"NSDPSContext: remove from dictionary\n"); + [GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread]; + } else - [GNU_CONTEXT_THREAD_DICT setObject: context - forKey: current_thread]; + { + NSLog(@"NSDPSContext: add to dictionary\n"); + [GNU_CONTEXT_THREAD_DICT setObject: context + forKey: current_thread]; + } [GNU_CONTEXT_LOCK unlock]; + NSLog(@"NSDPSContext: exit critical section\n"); + NSLog(@"NSDPSContext: return from +setCurrentContext\n"); } - (NSDPSContext *)DPSContext diff --git a/Source/NSView.m b/Source/NSView.m index ef96ccdc8..91fe225e9 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -31,6 +31,15 @@ #include #include #include +#include +#include +#include + +// +// Class variables +// +NSMutableDictionary *gnustep_gui_nsview_thread_dict; +NSRecursiveLock *gnustep_gui_nsview_lock; // NSView notifications NSString *NSViewFrameChangedNotification; @@ -52,15 +61,72 @@ NSString *NSViewFocusChangedNotification; // Initial version [self setVersion:1]; + + // Allocate dictionary for maintaining + // mapping of threads to focused views + gnustep_gui_nsview_thread_dict = [NSMutableDictionary dictionary]; + // Create lock for serializing access to dictionary + gnustep_gui_nsview_lock = [[NSRecursiveLock alloc] init]; } } // // Focusing // +// +++ Really each thread should have a stack! +// ++ (void)pushFocusView:(NSView *)focusView +{ + NSThread *current_thread = [NSThread currentThread]; + + NSLog(@"NSView: +pushFocusView\n"); + [gnustep_gui_nsview_lock lock]; + NSLog(@"NSView: enter critical section\n"); + + // If no context then remove from dictionary + if (!focusView) + { + NSLog(@"NSView: remove from dictionary\n"); + [gnustep_gui_nsview_thread_dict removeObjectForKey: current_thread]; + } + else + { + NSLog(@"NSView: add to dictionary\n"); + [gnustep_gui_nsview_thread_dict setObject: focusView + forKey: current_thread]; + } + + [gnustep_gui_nsview_lock unlock]; + NSLog(@"NSView: exit critical section\n"); + NSLog(@"NSView: return from +pushFocusView\n"); +} + ++ (NSView *)popFocusView +{} + + (NSView *)focusView { - return nil; + NSThread *current_thread = [NSThread currentThread]; + NSView *current_view = nil; + + NSLog(@"NSView: +focusView\n"); + // Get focused view for current thread + [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 + if (!current_view) + NSLog(@"NSView: Did not find a view\n"); + else + NSLog(@"NSView: Found a view\n"); + + [gnustep_gui_nsview_lock unlock]; + NSLog(@"NSView: exit critical section\n"); + + NSLog(@"NSView: return from +focusView\n"); + return current_view; } // @@ -151,7 +217,7 @@ NSString *NSViewFocusChangedNotification; - (void)addSubview:(NSView *)aView positioned:(NSWindowOrderingMode)place -relativeTo:(NSView *)otherView + relativeTo:(NSView *)otherView { // Not a NSView --then forget it if (![aView isKindOfClass:[NSView class]]) return; @@ -520,10 +586,12 @@ relativeTo:(NSView *)otherView // - (void)lockFocus { + [[self class] pushFocusView: self]; } - (void)unlockFocus { + [[self class] popFocusView]; } //