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> Fri Jan 7 11:03:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* GNUmakefile: Set Gorm_PRINCIPAL_CLASS * GNUmakefile: Set Gorm_PRINCIPAL_CLASS

View file

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

View file

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

4
Gorm.m
View file

@ -604,11 +604,13 @@ NSString *GormLinkPboardType = @"GormLinkPboardType";
- (id) newApplication: (id) sender - (id) newApplication: (id) sender
{ {
id doc = [GormDocument new]; id doc = [GormDocument new];
[documents addObject: doc]; [documents addObject: doc];
RELEASE(doc); RELEASE(doc);
[doc setupDefaults: @"Application"];
[[doc window] makeKeyAndOrderFront: self]; [[doc window] makeKeyAndOrderFront: self];
return doc; return doc;
} }

View file

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

View file

@ -945,8 +945,19 @@ static NSImage *classesImage = nil;
NSMapInsert(objToName, (void*)obj, (void*)name); NSMapInsert(objToName, (void*)obj, (void*)name);
if ([obj isKindOfClass: [NSWindow class]] == YES if ([obj isKindOfClass: [NSMenu class]] == YES)
|| [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]; [objectsView addObject: obj];
[[self openEditorForObject: obj] activate]; [[self openEditorForObject: obj] activate];
@ -1105,6 +1116,46 @@ static NSImage *classesImage = nil;
[self setSelectionFromEditor: 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 - (void) setName: (NSString*)aName forObject: (id)object
{ {
id oldObject; id oldObject;
@ -1368,20 +1419,41 @@ static NSImage *classesImage = nil;
- (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object - (NSWindow*) windowAndRect: (NSRect*)r forObject: (id)object
{ {
/*
* Get the window and rectangle for which link markup should be drawn.
*/
if ([objectsView containsObject: object] == YES) if ([objectsView containsObject: object] == YES)
{ {
NSRect rect = [objectsView rectForObject: object]; /*
* objects that exist in the document objects view must have their link
rect = [objectsView convertRect: rect toView: nil]; * markup drawn there, so we ask the view for the required rectangle.
*r = rect; */
*r = [objectsView rectForObject: object];
return [objectsView window]; 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) else if ([object isKindOfClass: [NSView class]] == YES)
{ {
NSRect rect = [object bounds]; /*
* Nowmal view objects just get link markup drawn on them.
rect = [object convertRect: rect toView: nil]; */
*r = rect; *r = [object convertRect: [object bounds] toView: nil];
return [object window]; return [object window];
} }
else else

View file

@ -558,29 +558,45 @@ selectCellWithString: (NSString*)title
{ {
if ([title isEqual: @"target"]) if ([title isEqual: @"target"])
{ {
if (actions == nil) id con = nil;
{ NSString *action;
actions = [[NSApp classManager] allActionsForObject:
[NSApp connectDestination]];
RETAIN(actions);
}
for (index = 0; index < numConnectors; index++) for (index = 0; index < numConnectors; index++)
{ {
id con = [connectors objectAtIndex: index]; con = [connectors objectAtIndex: index];
if ([con isKindOfClass: [NSNibControlConnector class]] == YES) if ([con isKindOfClass: [NSNibControlConnector class]] == YES)
{ {
NSString *action = [con label]; RELEASE(actions);
actions = RETAIN([[NSApp classManager]
ASSIGN(currentConnector, con); allActionsForObject: [con destination]]);
[newBrowser selectRow: [actions indexOfObject: action]
inColumn: 1];
[oldBrowser selectRow: index inColumn: 0];
[NSApp displayConnectionBetween: object
and: [con destination]];
break; 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 else
{ {
@ -593,12 +609,9 @@ selectCellWithString: (NSString*)title
{ {
id con = [connectors objectAtIndex: index]; id con = [connectors objectAtIndex: index];
if ([[con label] isEqual: title] == YES) if ([con label] == nil || [[con label] isEqual: title] == YES)
{ {
ASSIGN(currentConnector, con); ASSIGN(currentConnector, con);
[oldBrowser selectRow: index inColumn: 0];
[NSApp displayConnectionBetween: object
and: [con destination]];
found = YES; found = YES;
break; break;
} }
@ -613,10 +626,15 @@ selectCellWithString: (NSString*)title
[currentConnector setSource: object]; [currentConnector setSource: object];
[currentConnector setDestination: [NSApp connectDestination]]; [currentConnector setDestination: [NSApp connectDestination]];
[currentConnector setLabel: title]; [currentConnector setLabel: title];
[oldBrowser loadColumnZero];
[oldBrowser selectRow: index inColumn: 0];
} }
} }
/*
* Update the bottom browser.
*/
[oldBrowser loadColumnZero];
[oldBrowser selectRow: index inColumn: 0];
[NSApp displayConnectionBetween: object
and: [currentConnector destination]];
} }
else else
{ {
@ -848,6 +866,28 @@ selectCellWithString: (NSString*)title
} }
else 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]; [connectors addObject: currentConnector];
[[(id<IB>)NSApp activeDocument] addConnector: currentConnector]; [[(id<IB>)NSApp activeDocument] addConnector: currentConnector];
[currentConnector establishConnection]; [currentConnector establishConnection];
@ -911,6 +951,13 @@ selectCellWithString: (NSString*)title
[newBrowser selectRow: 0 inColumn: 0]; [newBrowser selectRow: 0 inColumn: 0];
} }
} }
else if ([currentConnector isKindOfClass:
[NSNibControlConnector class]] == YES)
{
[newBrowser selectRow: [outlets indexOfObject: @"target"]
inColumn: 0];
}
[self updateButtons]; [self updateButtons];
} }
} }

View file

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

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff