diff --git a/ChangeLog b/ChangeLog index 41d423615..b0eab3900 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,35 @@ -iThu Sep 9 1999 Nicola Pero +1999-09-10 Pedro Ivo Andrade Tavares + + * Source/NSHelpManager.m: new file. See below for an explanation. + * Headers/AppKit/NSHelpManager.h: new file. + * Source/GSHelpManagerPanel.h: new file. + * Source/GSHelpManagerPanel.m: new file, defines the help window + used by NSHelpManager. + * Source/NSWindow.m ([NSWindow -sendEvent:]): if we're in context + help mode, call -helpRequested: instead of -mouseDown. + * NSResponder.m ([NSResponder -helpRequested:]): if the current + responder has context help, show it using NSHelpManager; else, + pass to the next responder. + + These changes and new files implement the NSHelpManager context + help interface, which is defined on OpenStep 4.1 onward and Mac + OS X Server. + To define context help for any responder, call [[NSHelpManager + sharedHelpManager] setContextHelp: (an NSAttributedString with the + help) forObject: (the responder)]. For the user to see it, call + [[NSApplication sharedApplication] activateContextHelpMode] for + now, and the next time a user clicks on a responder, its help + will be shown. + The actiation of the context help mode will be automatic in the + future. + +1999-09-10 Michael Hanni + + * Source/NSTabView.m: fixed a display problem. Tabs on the bottom + of the view work, but some display niggles remain. (Note: we beat + Apple on this one, heh.) + +Thu Sep 9 1999 Nicola Pero * Source/NSButtonCell.m: implemented missing method ([-cellSize]). diff --git a/Headers/gnustep/gui/GSHelpManagerPanel.h b/Headers/gnustep/gui/GSHelpManagerPanel.h new file mode 100644 index 000000000..856eebf5f --- /dev/null +++ b/Headers/gnustep/gui/GSHelpManagerPanel.h @@ -0,0 +1,11 @@ +#import + +@interface GSHelpManagerPanel: NSPanel +{ + id textView; +} + ++sharedHelpManagerPanel; +-init; +-(void)setHelpText: (NSAttributedString*)helpText; +@end diff --git a/Headers/gnustep/gui/NSHelpManager.h b/Headers/gnustep/gui/NSHelpManager.h new file mode 100644 index 000000000..3d6244205 --- /dev/null +++ b/Headers/gnustep/gui/NSHelpManager.h @@ -0,0 +1,79 @@ +/* + NSHelpManager.m + + Description... + + Copyright (C) 1999 Free Software Foundation, Inc. + + Author: Pedro Ivo Andrade Tavares + Date: 1999 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef __GNUstep_H_NSHelpManager +#define __GNUstep_H_NSHelpManager + +#include +#include +#include + +@class NSAttributedString; + +@interface NSBundle (NSHelpManager) +- (NSAttributedString*) contextHelpForKey: (NSString*) key; +@end + +@interface NSApplication (NSHelpManager) +- (void) showHelp: (id) sender; +- (void) activateContextHelpMode: (id) sender; +@end + +@interface NSHelpManager: NSObject +{ +@private + NSMapTable* contextHelpTopics; +} + +// +// Class methods +// ++ (NSHelpManager*)sharedHelpManager; + ++ (BOOL)isContextHelpModeActive; + ++ (void)setContextHelpModeActive: (BOOL) flag; + +// +// Instance methods +// +- (NSAttributedString*) contextHelpForObject: (id)object; + +- (void) removeContextHelpForObject: (id)object; + +- (void) setContextHelp: (NSAttributedString*) help withObject: (id) object; + +- (BOOL) showContextHelpForObject: (id)object locationHint: (NSPoint) point; + +@end + +// Notifications +extern NSString* NSContextHelpModeDidActivateNotification; +extern NSString* NSContextHelpModeDidDeactivateNotification; + +#endif // GNUstep_H_NSHelpManager diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 81b41c771..3eb3aa480 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -75,6 +75,7 @@ NSForm.m \ NSFormCell.m \ NSGraphicsContext.m \ NSHelpPanel.m \ +NSHelpManager.m \ NSImage.m \ NSImageCell.m \ NSImageRep.m \ @@ -126,6 +127,7 @@ NSView.m \ NSWindow.m \ NSWorkspace.m \ GSComboSupport.m \ +GSHelpManagerPanel.m \ GSTextStorage.m \ GSTrackingRect.m \ GSServicesManager.m \ @@ -181,6 +183,7 @@ AppKit/NSFormCell.h \ AppKit/NSGraphics.h \ AppKit/NSGraphicsContext.h \ AppKit/NSHelpPanel.h \ +AppKit/NSHelpManager.h \ AppKit/NSImage.h \ AppKit/NSImageCell.h \ AppKit/NSImageRep.h \ diff --git a/Source/GSHelpManagerPanel.m b/Source/GSHelpManagerPanel.m new file mode 100644 index 000000000..06763a2f4 --- /dev/null +++ b/Source/GSHelpManagerPanel.m @@ -0,0 +1,85 @@ +#import +#import + +@implementation GSHelpManagerPanel +{ + id textView; +} + +static GSHelpManagerPanel* _GSsharedGSHelpPanel; + ++sharedHelpManagerPanel +{ + if(!_GSsharedGSHelpPanel) + _GSsharedGSHelpPanel = [[GSHelpManagerPanel alloc] init]; + return _GSsharedGSHelpPanel; +} + +/* This window should not be destroyed... So we don't allow it to! */ +-retain +{ + return self; +} + +-release +{ + return self; +} + +-autorelease +{ + return self; +} + +-init +{ + NSScrollView* scrollView; + NSRect scrollViewRect = {{0, 0}, {470, 150}}; + NSRect winRect = {{100, 100}, {470, 150}}; + NSColor* backColor; + unsigned int style = NSTitledWindowMask | NSClosableWindowMask + | NSMiniaturizableWindowMask | NSResizableWindowMask; + + [self initWithContentRect:winRect + styleMask:style + backing:NSBackingStoreRetained + defer:NO]; + [self setRepresentedFilename: @"Help"]; + [self setDocumentEdited: NO]; + + scrollView = [[NSScrollView alloc] initWithFrame:scrollViewRect]; + [scrollView setHasHorizontalScroller:NO]; + [scrollView setHasVerticalScroller:YES]; + [scrollView setAutoresizingMask: NSViewHeightSizable]; + + textView = [NSText new]; + [textView setEditable: NO]; + [textView setRichText: YES]; + [textView setSelectable: YES]; + [textView setFrame:[[scrollView contentView] frame]]; + backColor = [NSColor colorWithCalibratedWhite:0.85 alpha:1.0]; // off white + [textView setBackgroundColor:backColor]; + [scrollView setDocumentView:textView]; + [[self contentView] addSubview: scrollView]; + + [self setTitle:@"Help"]; + + return self; +} + +-(void)setHelpText: (NSAttributedString*) helpText +{ + [textView setText: [helpText string]]; +} + +-(BOOL) isFloatingPanel +{ + return YES; +} + +-(void) close +{ + [NSApp stopModal]; + [super close]; +} +@end diff --git a/Source/NSHelpManager.m b/Source/NSHelpManager.m new file mode 100644 index 000000000..ee4f5ebae --- /dev/null +++ b/Source/NSHelpManager.m @@ -0,0 +1,174 @@ +/* + NSHelpManager.m + + NSHelpManager is the class responsible for managing context help + for the application, and its mapping to the graphic elements. + + Copyright (C) 1999 Free Software Foundation, Inc. + + Author: Pedro Ivo Andrade Tavares + Date: September 1999 + + This file is part of the GNUstep GUI Library. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +@implementation NSBundle (NSHelpManager) + +- (NSAttributedString*) contextHelpForKey: (NSString*) key +{ + // FIXME + /* There are some issues here. I still have to understand how + does Help.plist work. */ + NSLog(@"contextHelpForKey not implemented yet."); + return nil; +} + +@end + +@implementation NSApplication (NSHelpManager) + +- (void) showHelp: (id)sender +{ + // FIXME + /* This is obviously very restrictive. The ideal would be to check + the Resources first, but this can be done later. */ + [[NSWorkspace sharedWorkspace] openFile: @"Help.rtf"]; +} + +- (void) activateContextHelpMode: (id)sender +{ + [NSHelpManager setContextHelpModeActive: YES]; +} + +@end + +@implementation NSHelpManager +{ +@private + NSMapTable* contextHelpTopics; +} + +static NSHelpManager *_gnu_sharedHelpManager = nil; +static BOOL _gnu_contextHelpActive = NO; + + +// +// Class methods +// ++ (NSHelpManager*)sharedHelpManager +{ + if (!_gnu_sharedHelpManager) + { + _gnu_sharedHelpManager = [NSHelpManager alloc]; + [_gnu_sharedHelpManager init]; + } + return _gnu_sharedHelpManager; +} + ++ (BOOL)isContextHelpModeActive +{ + return _gnu_contextHelpActive; +} + ++ (void)setContextHelpModeActive: (BOOL) flag +{ + _gnu_contextHelpActive = flag; + if (flag) + { + [[NSNotificationCenter defaultCenter] + postNotificationName: NSContextHelpModeDidActivateNotification + object: [self sharedHelpManager]]; + } + else + { + [[NSNotificationCenter defaultCenter] + postNotificationName: NSContextHelpModeDidDeactivateNotification + object: [self sharedHelpManager]]; + } +} + +// +// Instance methods +// +- (id) init +{ + contextHelpTopics = NSCreateMapTable(NSObjectMapKeyCallBacks, + NSObjectMapValueCallBacks, + 64); + return self; +} + +- (NSAttributedString*) contextHelpForObject: (id)object +{ + /* Help is kept on the contextHelpTopics NSMapTable, with + the object for it as the key. + + Help is loaded on demand: + If it's an NSAttributedString which is stored, then it's already + loaded. + If it's nil, there's no help for this object, and that's what we return. + If it's an NSString, it's the path for the help, and we ask NSBundle + for it (This part has to be written, so:) */ + // FIXME + + id hc = NSMapGet(contextHelpTopics, object); + if(hc) + { + if(![hc isKindOfClass: [NSAttributedString class]]) + { + hc = [[NSBundle mainBundle] contextHelpForKey: hc]; + NSMapInsert(contextHelpTopics, object, hc); + } + } + return hc; +} + +- (void) removeContextHelpForObject: (id)object +{ + NSMapRemove(contextHelpTopics, object); +} + +- (void) setContextHelp: (NSAttributedString*) help withObject: (id) object +{ + NSMapInsert(contextHelpTopics, object, help); +} + +- (BOOL) showContextHelpForObject: (id)object locationHint: (NSPoint) point +{ + id contextHelp = [self contextHelpForObject: object]; + if (contextHelp) + { + [[GSHelpManagerPanel sharedHelpManagerPanel] setHelpText: contextHelp]; + [NSApp runModalForWindow: [GSHelpManagerPanel sharedHelpManagerPanel]]; + return YES; + } + else return NO; +} + +@end diff --git a/Source/NSResponder.m b/Source/NSResponder.m index 9f3a7776f..2bc4499bf 100644 --- a/Source/NSResponder.m +++ b/Source/NSResponder.m @@ -32,6 +32,7 @@ #include #include #include +#include #include @implementation NSResponder @@ -122,10 +123,15 @@ - (void) helpRequested: (NSEvent *)theEvent { + if([[NSHelpManager sharedHelpManager] + showContextHelpForObject: self + locationHint: [theEvent locationInWindow]]) + { + [NSHelpManager setContextHelpModeActive: NO]; + } + else if (next_responder) return [next_responder helpRequested: theEvent]; - else - return [self noResponderFor: @selector(helpRequested:)]; } - (void) keyDown: (NSEvent *)theEvent diff --git a/Source/NSTabView.m b/Source/NSTabView.m index e87cfa7f1..578b7c1d7 100644 --- a/Source/NSTabView.m +++ b/Source/NSTabView.m @@ -154,6 +154,9 @@ tab_selected_item = [tab_items indexOfObject:tab_selected]; [tab_selected _setTabState:NSSelectedTab]; + + [self setNeedsDisplay:YES]; + if ([tab_selected view]) [self addSubview:[tab_selected view]]; @@ -162,8 +165,6 @@ { [tab_delegate tabView:self didSelectTabViewItem:tab_selected]; } - - [self setNeedsDisplay:YES]; } } @@ -571,7 +572,7 @@ // [self setNeedsDisplay:YES]; - [window update]; +// [window update]; return [super hitTest:aPoint]; } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 6c7243772..b0499f113 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -56,6 +56,7 @@ #include #include #include +#include BOOL GSViewAcceptsDrag(NSView *v, id dragInfo); @@ -1446,10 +1447,28 @@ static NSRecursiveLock *windowsLock; { [self makeFirstResponder: v]; if (is_key || [v acceptsFirstMouse: theEvent] == YES) - [v mouseDown: theEvent]; + { + if([NSHelpManager isContextHelpModeActive]) + { + [v helpRequested: theEvent]; + } + else + { + [v mouseDown: theEvent]; + } + } } else - [v mouseDown: theEvent]; + { + if([NSHelpManager isContextHelpModeActive]) + { + [v helpRequested: theEvent]; + } + else + { + [v mouseDown: theEvent]; + } + } last_point = [theEvent locationInWindow]; break; diff --git a/Source/externs.m b/Source/externs.m index 57a1b37ec..2ab2f618a 100644 --- a/Source/externs.m +++ b/Source/externs.m @@ -130,6 +130,12 @@ NSString *NSControlTextDidChangeNotification = // NSDataLink global strings NSString *NSDataLinkFileNameExtension = @"dlf"; +// NSHelpManager notifications; +NSString *NSContextHelpModeDidActivateNotification = +@"NSContextHelpModeDidActivateNotification"; +NSString *NSContextHelpModeDidDeactivateNotification = +@"NSContextHelpModeDidDeactivateNotification"; + // NSFont Global Strings NSString *NSAFMAscender = @"Ascender"; NSString *NSAFMCapHeight = @"CapHeight";