Limited menu support

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@5741 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2000-01-13 21:19:03 +00:00
parent 5e63479fbd
commit 308f97b6ba
10 changed files with 920 additions and 1300 deletions

View file

@ -1,3 +1,7 @@
Thu Jan 13 20:34:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Preliminary menu support (very limited).
Fri Jan 7 11:03:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* GNUmakefile: Set Gorm_PRINCIPAL_CLASS

View file

@ -21,6 +21,15 @@
);
Super = NSView;
};
NSMenu = {
Super = NSObject;
};
NSMenuItem = {
Outlets = (
target
);
Super = NSObject;
};
NSSlider = {
Super = NSControl;
};

View file

@ -37,7 +37,6 @@ SUBPROJECTS = \
#
APP_NAME = Gorm
Gorm_PRINCIPAL_CLASS=Gorm
Gorm_MAIN_MODEL_FILE=Gorm.gorm
Gorm_APPLICATION_ICON=Gorm.tiff
Gorm_RESOURCE_FILES = \
ClassInformation.plist \

2
Gorm.m
View file

@ -608,7 +608,9 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
[documents addObject: doc];
RELEASE(doc);
[doc setupDefaults: @"Application"];
[[doc window] makeKeyAndOrderFront: self];
return doc;
}

View file

@ -31,6 +31,7 @@
NSScrollView *scrollView;
id objectsView;
BOOL hiddenDuringTest;
BOOL hasSetDefaults;
BOOL isActive;
NSMenu *savedMenu;
NSMenuItem *quitItem; /* Replaced during test */
@ -75,6 +76,7 @@
- (id) revertDocument: (id)sender;
- (id) saveAsDocument: (id)sender;
- (id) saveDocument: (id)sender;
- (void) setupDefaults: (NSString*)type;
- (void) setDocumentActive: (BOOL)flag;
- (void) setName: (NSString*)aName forObject: (id)object;
- (void) setObject: (id)anObject isVisibleAtLaunch: (BOOL)flag;

View file

@ -945,8 +945,19 @@ static NSImage *classesImage = nil;
NSMapInsert(objToName, (void*)obj, (void*)name);
if ([obj isKindOfClass: [NSWindow class]] == YES
|| [obj isKindOfClass: [NSMenu class]] == YES)
if ([obj isKindOfClass: [NSMenu class]] == YES)
{
[objectsView addObject: obj];
if ([name isEqual: @"NSMenu"] == YES)
{
NSRect frame = [[NSScreen mainScreen] frame];
[[obj window] setFrameTopLeftPoint:
NSMakePoint(1, frame.size.height-200)];
[[self openEditorForObject: obj] activate];
}
}
else if ([obj isKindOfClass: [NSWindow class]] == YES)
{
[objectsView addObject: obj];
[[self openEditorForObject: obj] activate];
@ -1105,6 +1116,46 @@ static NSImage *classesImage = nil;
[self setSelectionFromEditor: nil];
}
- (void) setupDefaults: (NSString*)type
{
if (hasSetDefaults == YES)
{
return;
}
hasSetDefaults = YES;
if ([type isEqual: @"Application"] == YES)
{
NSMenu *aMenu = [NSMenu new];
NSWindow *aWindow;
NSRect frame = [[NSScreen mainScreen] frame];
unsigned style = NSTitledWindowMask | NSClosableWindowMask
| NSResizableWindowMask | NSMiniaturizableWindowMask;
aWindow = [[NSWindow alloc] initWithContentRect: NSMakeRect(0,0,600, 400)
styleMask: style
backing: NSBackingStoreRetained
defer: NO];
[aWindow setFrameTopLeftPoint:
NSMakePoint(220, frame.size.height-100)];
[aWindow setTitle: @"My Window"];
[self attachObject: aWindow toParent: nil];
RELEASE(aWindow);
[aMenu setTitle: @"Main Menu"];
[aMenu addItemWithTitle: @"Hide"
action: @selector(hide:)
keyEquivalent: @"h"];
[aMenu addItemWithTitle: @"Quit"
action: @selector(terminate:)
keyEquivalent: @"q"];
[self setName: @"NSMenu" forObject: aMenu];
[self attachObject: aMenu toParent: nil];
[[aMenu window] setFrameTopLeftPoint:
NSMakePoint(1, frame.size.height-200)];
RELEASE(aMenu);
}
}
- (void) setName: (NSString*)aName forObject: (id)object
{
id oldObject;
@ -1368,20 +1419,41 @@ static NSImage *classesImage = nil;
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object
{
/*
* Get the window and rectangle for which link markup should be drawn.
*/
if ([objectsView containsObject: object] == YES)
{
NSRect rect = [objectsView rectForObject: object];
rect = [objectsView convertRect: rect toView: nil];
*r = rect;
/*
* objects that exist in the document objects view must have their link
* markup drawn there, so we ask the view for the required rectangle.
*/
*r = [objectsView rectForObject: object];
return [objectsView window];
}
else if ([object isKindOfClass: [NSMenuItem class]] == YES)
{
NSArray *links;
NSMenu *menu;
id editor;
/*
* Menu items must have their markup drawn in the window of the
* editor of the parent menu.
*/
links = [self connectorsForSource: object
ofClass: [NSNibConnector class]];
menu = [[links lastObject] destination];
editor = [self editorForObject: menu create: NO];
*r = [editor rectForObject: object];
return [editor window];
}
else if ([object isKindOfClass: [NSView class]] == YES)
{
NSRect rect = [object bounds];
rect = [object convertRect: rect toView: nil];
*r = rect;
/*
* Nowmal view objects just get link markup drawn on them.
*/
*r = [object convertRect: [object bounds] toView: nil];
return [object window];
}
else

View file

@ -558,29 +558,45 @@ selectCellWithString: (NSString*)title
{
if ([title isEqual: @"target"])
{
if (actions == nil)
{
actions = [[NSApp classManager] allActionsForObject:
[NSApp connectDestination]];
RETAIN(actions);
}
id con = nil;
NSString *action;
for (index = 0; index < numConnectors; index++)
{
id con = [connectors objectAtIndex: index];
con = [connectors objectAtIndex: index];
if ([con isKindOfClass: [NSNibControlConnector class]] == YES)
{
NSString *action = [con label];
ASSIGN(currentConnector, con);
[newBrowser selectRow: [actions indexOfObject: action]
inColumn: 1];
[oldBrowser selectRow: index inColumn: 0];
[NSApp displayConnectionBetween: object
and: [con destination]];
RELEASE(actions);
actions = RETAIN([[NSApp classManager]
allActionsForObject: [con destination]]);
break;
}
}
if (con == nil)
{
RELEASE(actions);
actions = RETAIN([[NSApp classManager]
allActionsForObject: [NSApp connectDestination]]);
if ([actions count] > 0)
{
con = [NSNibControlConnector new];
[con setSource: object];
[con setDestination: [NSApp connectDestination]];
[con setLabel: [actions objectAtIndex: 0]];
AUTORELEASE(con);
}
}
if (currentConnector != con)
{
ASSIGN(currentConnector, con);
[newBrowser setLastColumn: 0];
}
action = [con label];
if (action != nil)
{
[newBrowser selectRow: [actions indexOfObject: action]
inColumn: 1];
}
}
else
{
@ -593,12 +609,9 @@ selectCellWithString: (NSString*)title
{
id con = [connectors objectAtIndex: index];
if ([[con label] isEqual: title] == YES)
if ([con label] == nil || [[con label] isEqual: title] == YES)
{
ASSIGN(currentConnector, con);
[oldBrowser selectRow: index inColumn: 0];
[NSApp displayConnectionBetween: object
and: [con destination]];
found = YES;
break;
}
@ -613,10 +626,15 @@ selectCellWithString: (NSString*)title
[currentConnector setSource: object];
[currentConnector setDestination: [NSApp connectDestination]];
[currentConnector setLabel: title];
}
}
/*
* Update the bottom browser.
*/
[oldBrowser loadColumnZero];
[oldBrowser selectRow: index inColumn: 0];
}
}
[NSApp displayConnectionBetween: object
and: [currentConnector destination]];
}
else
{
@ -848,6 +866,28 @@ selectCellWithString: (NSString*)title
}
else
{
/*
* Establishing a target/action type connection will automatically
* remove any previous target/action connection.
*/
if ([currentConnector isKindOfClass: [NSNibControlConnector class]])
{
NSEnumerator *enumerator = [connectors objectEnumerator];
id con;
while ((con = [enumerator nextObject]) != nil)
{
if ([con isKindOfClass: [NSNibControlConnector class]])
{
[[(id<IB>)NSApp activeDocument] removeConnector: con];
[con setDestination: nil];
[con setLabel: nil];
[con establishConnection];
[connectors removeObjectIdenticalTo: con];
break;
}
}
}
[connectors addObject: currentConnector];
[[(id<IB>)NSApp activeDocument] addConnector: currentConnector];
[currentConnector establishConnection];
@ -911,6 +951,13 @@ selectCellWithString: (NSString*)title
[newBrowser selectRow: 0 inColumn: 0];
}
}
else if ([currentConnector isKindOfClass:
[NSNibControlConnector class]] == YES)
{
[newBrowser selectRow: [outlets indexOfObject: @"target"]
inColumn: 0];
}
[self updateButtons];
}
}

View file

@ -538,6 +538,7 @@ static NSMapTable *docMap = 0;
/*
* Return the rectangle in which an objects image will be displayed.
* (use window coordinates)
*/
- (NSRect) rectForObject: (id)anObject
{
@ -556,6 +557,7 @@ static NSMapTable *docMap = 0;
*/
rect.size.width -= 15;
rect.size.height -= 15;
rect = [self convertRect: rect toView: nil];
return rect;
}

View file

@ -52,31 +52,16 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
return r;
}
/*
* Methods to return the images that should be used to display objects within
* the matrix containing the objects in a document.
*/
@implementation NSMenu (GormObjectAdditions)
- (NSImage*) imageForViewer
{
static NSImage *image = nil;
if (image == nil)
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForImageResource: @"GormMenu"];
image = [[NSImage alloc] initWithContentsOfFile: path];
}
return image;
}
@end
@implementation NSWindow (GormObjectAdditions)
- (NSString*) editorClassName
{
return @"GormWindowEditor";
}
/*
* Method to return the image that should be used to display windows within
* the matrix containing the objects in a document.
*/
- (NSImage*) imageForViewer
{
static NSImage *image = nil;
@ -174,10 +159,6 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
- (BOOL) acceptsFirstMouse: (NSEvent*)theEvent
{
if ([(id<IB>)NSApp isTestingInterface] == YES)
{
return NO;
}
return YES;
}
@ -192,12 +173,6 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
*/
- (NSView*) hitTest: (NSPoint)loc
{
if ([(id<IB>)NSApp isTestingInterface] == YES)
{
return [super hitTest: loc];
}
else
{
/*
* Stop the subviews receiving events - we grab them all.
*/
@ -206,18 +181,10 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
return self;
}
return nil;
}
}
- (void) mouseDown: (NSEvent*)theEvent
{
if ([(id<IB>)NSApp isTestingInterface] == YES)
{
[super mouseDown: theEvent];
return;
}
else
{
NSEnumerator *enumerator;
NSView *view = nil;
IBKnobPosition knob = IBNoneKnobPosition;
@ -746,7 +713,6 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
[[self window] setAcceptsMouseMovedEvents: acceptsMouseMoved];
}
[self makeSelectionVisible: YES];
}
}
- (BOOL) acceptsTypeFromArray: (NSArray*)types
@ -1176,7 +1142,7 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
- (void) selectObjects: (NSArray*)anArray
{
if (anArray != selection)
if ([anArray isEqual: selection] == NO)
{
unsigned count;
@ -1197,6 +1163,7 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
[selection removeObjectAtIndex: count];
}
}
}
/*
* Now we must let the document (and hence the rest of the app) know
* about our new selection. If there is nothing in it, make sure
@ -1213,7 +1180,6 @@ NSRectFromPoints(NSPoint p0, NSPoint p1)
ed = [GormObjectEditor editorForDocument: document];
[ed selectObjects: [NSArray arrayWithObject: edited]];
}
}
}
- (NSArray*) selection

File diff suppressed because it is too large Load diff