From c0b92c18ee30deef0e2c9bc4d11be9a9eb148b7d Mon Sep 17 00:00:00 2001 From: netcrep Date: Thu, 3 Oct 1996 18:45:41 +0000 Subject: [PATCH] Fill out implementation of NSMenu, NSMatrix and NSWindow. Many bug fixes for NSMatrix. Assign values for global exception and notification strings. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@1842 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 19 +- Headers/gnustep/gui/NSWindow.h | 29 +- Source/NSApplication.m | 121 +++--- Source/NSMatrix.m | 676 ++++++++++++++++++++------------- Source/NSMenu.m | 12 +- Source/NSWindow.m | 280 +++++++++----- 6 files changed, 725 insertions(+), 412 deletions(-) diff --git a/ChangeLog b/ChangeLog index c456b14ac..6ca25c931 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,21 @@ -Sat Sep 21 12:25:23 1996 GNUstep Development +Wed Oct 2 10:40:23 1996 GNUstep Development + + * Headers/gnustep/gui/NSWindow.h: Add additional instance variables + to fill out implementation. + (-initDefaults): New method. + * Source/NSApplication.m: Assign values to the global exception and + notification strings. Post notifications to the default notification + center. Fixed bug where the first event was being removed from the + queue versus removing the event actually being processed. + * Source/NSMatrix.m: Fill out implementation, reimplement many + methods, and fix lots of bugs. + * Source/NSMenu.m: Don't create NSView as content view, just make + the menu matrix the content view. + * Source/NSWindow.m: Assign values to the notification strings. + Implement many unimplemented methods. Post notifications to the + default notification center. + +Sat Sep 21 12:25:23 1996 GNUstep Development * Source/NSButtonCell.m (-initTextCell:): Make default font be the user font instead of the user fixed pitch font. diff --git a/Headers/gnustep/gui/NSWindow.h b/Headers/gnustep/gui/NSWindow.h index 526190258..2668d9f68 100644 --- a/Headers/gnustep/gui/NSWindow.h +++ b/Headers/gnustep/gui/NSWindow.h @@ -49,7 +49,8 @@ { // Attributes NSRect frame; - id frame_view; + NSSize minimum_size; + NSSize maximum_size; id content_view; id first_responder; id original_responder; @@ -58,18 +59,33 @@ NSColor *background_color; NSString *represented_filename; NSString *miniaturized_title; + NSImage *miniaturized_image; NSString *window_title; NSPoint last_point; NSBackingStoreType backing_type; + unsigned int style_mask; + int window_level; + + BOOL is_one_shot; + BOOL needs_display; + BOOL is_autodisplay; + BOOL optimize_drawing; + BOOL views_need_display; + NSWindowDepth depth_limit; + BOOL dynamic_depth_limit; + + BOOL cursor_rects_enabled; BOOL visible; BOOL is_key; BOOL is_main; BOOL is_edited; + BOOL is_released_when_closed; BOOL is_miniaturized; BOOL disable_flush_window; - unsigned int style_mask; BOOL menu_exclude; + BOOL hides_on_deactivate; + BOOL accepts_mouse_moved; // Reserved for back-end use void *be_wind_reserved; @@ -315,7 +331,7 @@ // // Printing and postscript // -- (NSDate *)dataWithEPSInsideRect:(NSRect)rect; +- (NSData *)dataWithEPSInsideRect:(NSRect)rect; - (void)fax:sender; - (void)print:sender; @@ -354,9 +370,13 @@ - (void)encodeWithCoder:aCoder; - initWithCoder:aDecoder; +@end + // -// GNUstep additional methods +// GNUstep backend methods // +@interface NSWindow (GNUstepBackend) + // // Mouse capture/release // @@ -365,6 +385,7 @@ // Allow subclasses to init without the backend class // attempting to create an actual window +- (void)initDefaults; - cleanInit; @end diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 2feeec7cc..c0b8f0c79 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -48,56 +48,62 @@ NSString *NSEventTrackingRunLoopMode = @"EventTrackingMode"; // // Global Exception Strings // -NSString *NSAbortModalException = @"AbortModalException"; -NSString *NSAbortPrintingException = @"AbortPrintingException"; -NSString *NSAppKitIgnoredException; -NSString *NSAppKitVirtualMemoryException; -NSString *NSBadBitmapParametersException; -NSString *NSBadComparisonException; -NSString *NSBadRTFColorTableException; -NSString *NSBadRTFDirectiveException; -NSString *NSBadRTFFontTableException; -NSString *NSBadRTFStyleSheetException; -NSString *NSBrowserIllegalDelegateException; -NSString *NSColorListIOException; -NSString *NSColorListNotEditableException; -NSString *NSDraggingException; -NSString *NSFontUnavailableException; -NSString *NSIllegalSelectorException; -NSString *NSImageCacheException; -NSString *NSNibLoadingException; -NSString *NSPPDIncludeNotFoundException; -NSString *NSPPDIncludeStackOverflowException; -NSString *NSPPDIncludeStackUnderflowException; -NSString *NSPPDParseException; -NSString *NSPasteboardCommunicationException; -NSString *NSPrintOperationExistsException; -NSString *NSPrintPackageException; -NSString *NSPrintingCommunicationException; -NSString *NSRTFPropertyStackOverflowException; -NSString *NSTIFFException; -NSString *NSTextLineTooLongException; -NSString *NSTextNoSelectionException; -NSString *NSTextReadException; -NSString *NSTextWriteException; -NSString *NSTypedStreamVersionException; -NSString *NSWindowServerCommunicationException; -NSString *NSWordTablesReadException; -NSString *NSWordTablesWriteException; +NSString *NSAbortModalException = @"AbortModal"; +NSString *NSAbortPrintingException = @"AbortPrinting"; +NSString *NSAppKitIgnoredException = @"AppKitIgnored"; +NSString *NSAppKitVirtualMemoryException = @"AppKitVirtualMemory"; +NSString *NSBadBitmapParametersException = @"BadBitmapParameters"; +NSString *NSBadComparisonException = @"BadComparison"; +NSString *NSBadRTFColorTableException = @"BadRTFColorTable"; +NSString *NSBadRTFDirectiveException = @"BadRTFDirective"; +NSString *NSBadRTFFontTableException = @"BadRTFFontTable"; +NSString *NSBadRTFStyleSheetException = @"BadRTFStyleSheet"; +NSString *NSBrowserIllegalDelegateException = @"BrowserIllegalDelegate"; +NSString *NSColorListIOException = @"ColorListIO"; +NSString *NSColorListNotEditableException = @"ColorListNotEditable"; +NSString *NSDraggingException = @"Draggin"; +NSString *NSFontUnavailableException = @"FontUnavailable"; +NSString *NSIllegalSelectorException = @"IllegalSelector"; +NSString *NSImageCacheException = @"ImageCache"; +NSString *NSNibLoadingException = @"NibLoading"; +NSString *NSPPDIncludeNotFoundException = @"PPDIncludeNotFound"; +NSString *NSPPDIncludeStackOverflowException = @"PPDIncludeStackOverflow"; +NSString *NSPPDIncludeStackUnderflowException = @"PPDIncludeStackUnderflow"; +NSString *NSPPDParseException = @"PPDParse"; +NSString *NSPasteboardCommunicationException = @"PasteboardCommunication"; +NSString *NSPrintOperationExistsException = @"PrintOperationExists"; +NSString *NSPrintPackageException = @"PrintPackage"; +NSString *NSPrintingCommunicationException = @"PrintingCommunication"; +NSString *NSRTFPropertyStackOverflowException = @"RTFPropertyStackOverflow"; +NSString *NSTIFFException = @"TIFF"; +NSString *NSTextLineTooLongException = @"TextLineTooLong"; +NSString *NSTextNoSelectionException = @"TextNoSelection"; +NSString *NSTextReadException = @"TextRead"; +NSString *NSTextWriteException = @"TextWrite"; +NSString *NSTypedStreamVersionException = @"TypedStreamVersion"; +NSString *NSWindowServerCommunicationException = @"WindowServerCommunication"; +NSString *NSWordTablesReadException = @"WordTablesRead"; +NSString *NSWordTablesWriteException = @"WordTablesWrite"; // Application notifications -NSString *NSApplicationDidBecomeActiveNotification; -NSString *NSApplicationDidFinishLaunchingNotification; -NSString *NSApplicationDidHideNotification; -NSString *NSApplicationDidResignActiveNotification; -NSString *NSApplicationDidUnhideNotification; -NSString *NSApplicationDidUpdateNotification; -NSString *NSApplicationWillBecomeActiveNotification; -NSString *NSApplicationWillFinishLaunchingNotification; -NSString *NSApplicationWillHideNotification; -NSString *NSApplicationWillResignActiveNotification; -NSString *NSApplicationWillUnhideNotification; -NSString *NSApplicationWillUpdateNotification; +NSString *NSApplicationDidBecomeActiveNotification + = @"ApplicationDidBecomeActive"; +NSString *NSApplicationDidFinishLaunchingNotification + = @"ApplicationDidFinishLaunching"; +NSString *NSApplicationDidHideNotification = @"ApplicationDidHide"; +NSString *NSApplicationDidResignActiveNotification + = @"ApplicationDidResignActive"; +NSString *NSApplicationDidUnhideNotification = @"ApplicationDidUnhide"; +NSString *NSApplicationDidUpdateNotification = @"ApplicationDidUpdate"; +NSString *NSApplicationWillBecomeActiveNotification + = @"ApplicationWillBecomeActive"; +NSString *NSApplicationWillFinishLaunchingNotification + = @"ApplicationWillFinishLaunching"; +NSString *NSApplicationWillHideNotification = @"ApplicationWillHide"; +NSString *NSApplicationWillResignActiveNotification + = @"ApplicationWillResignActive"; +NSString *NSApplicationWillUnhideNotification = @"ApplicationWillUnhide"; +NSString *NSApplicationWillUpdateNotification = @"ApplicationWillUpdate"; @implementation NSApplication @@ -164,13 +170,17 @@ NSString *NSApplicationWillUpdateNotification; - (void)finishLaunching { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // notify that we will finish the launching - [self applicationWillFinishLaunching:self]; + [nc postNotificationName: NSApplicationWillFinishLaunchingNotification + object: self]; - // finish the launching + // finish the launching - // notify that the launching has finished - [self applicationDidFinishLaunching:self]; + // notify that the launching has finished + [nc postNotificationName: NSApplicationDidFinishLaunchingNotification + object: self]; } - (void)dealloc @@ -352,6 +362,9 @@ NSString *NSApplicationWillUpdateNotification; if (!theEvent) return NO; + // Don't check the null event + if (theEvent == NullEvent) return NO; + t = [theEvent type]; if ((t == NSLeftMouseDown) && (mask & NSLeftMouseDownMask)) @@ -451,7 +464,9 @@ NSString *NSApplicationWillUpdateNotification; if ([self event: e matchMask: mask]) { if (e) - e = [event_queue dequeueObject]; + { + [event_queue removeObject: e]; + } done = YES; } } diff --git a/Source/NSMatrix.m b/Source/NSMatrix.m index a82637443..7bc8f5ea2 100644 --- a/Source/NSMatrix.m +++ b/Source/NSMatrix.m @@ -47,13 +47,16 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; + (void)initialize { - if (self == [NSMatrix class]) - { - NSDebugLog(@"Initialize NSMatrix class\n"); + if (self == [NSMatrix class]) + { + NSDebugLog(@"Initialize NSMatrix class\n"); - // Set initial version - [self setVersion: 1]; - } + // Set initial version + [self setVersion: 1]; + + // Set the default cell class + NSMATRIX_DEFAULT_CELL_CLASS = [NSCell class]; + } } // @@ -74,51 +77,51 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; // - (void)createInitialMatrix { - NSSize cs; - int i, j; - id aRow, aFloat; + NSSize cs; + int i, j; + id aRow, aFloat; - // Determine cell width and height for uniform cell size - cs.width = (frame.size.width - (inter_cell.width * (num_cols - 1))) - / num_cols; - cs.height = (frame.size.height - (inter_cell.height * (num_rows - 1))) - / num_rows; + // Determine cell width and height for uniform cell size + cs.width = (frame.size.width - (inter_cell.width * (num_cols - 1))) + / num_cols; + cs.height = (frame.size.height - (inter_cell.height * (num_rows - 1))) + / num_rows; - // Save cell widths and heights in arrays - aFloat = [NSNumber numberWithFloat: cs.height]; - for (i = 0;i < num_rows; ++i) - [row_heights addObject:aFloat]; - aFloat = [NSNumber numberWithFloat: cs.width]; - for (i = 0;i < num_cols; ++i) - [col_widths addObject:aFloat]; + // Save cell widths and heights in arrays + aFloat = [NSNumber numberWithFloat: cs.height]; + for (i = 0;i < num_rows; ++i) + [row_heights addObject:aFloat]; + aFloat = [NSNumber numberWithFloat: cs.width]; + for (i = 0;i < num_cols; ++i) + [col_widths addObject:aFloat]; - for (i = 0;i < num_rows; ++i) + for (i = 0;i < num_rows; ++i) + { + aRow = [NSMutableArray arrayWithCapacity: num_cols]; + [rows addObject: aRow]; + for (j = 0;j < num_cols; ++j) { - aRow = [NSMutableArray arrayWithCapacity: num_cols]; - [rows addObject: aRow]; - for (j = 0;j < num_cols; ++j) - { - if (cell_prototype != nil) - { - [(NSMutableArray *)aRow addObject: - [cell_prototype copy]]; - } - else - { - [(NSMutableArray *)aRow addObject: - [[cell_class alloc] init]]; - } - } + if (cell_prototype != nil) + { + [(NSMutableArray *)aRow addObject: + [cell_prototype copy]]; + } + else + { + [(NSMutableArray *)aRow addObject: + [[cell_class alloc] init]]; + } } + } } - (id)initWithFrame:(NSRect)frameRect { - return [self initWithFrame:frameRect - mode:NSTrackModeMatrix - cellClass:[NSCell class] - numberOfRows:0 - numberOfColumns:0]; + return [self initWithFrame: frameRect + mode: NSTrackModeMatrix + cellClass: NSMATRIX_DEFAULT_CELL_CLASS + numberOfRows: 0 + numberOfColumns: 0]; } - (id)initWithFrame:(NSRect)frameRect @@ -127,48 +130,49 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; numberOfRows:(int)rowsHigh numberOfColumns:(int)colsWide { - NSDebugLog(@"NSMatrix start -initWithFrame: ..cellClass:\n"); + NSDebugLog(@"NSMatrix start -initWithFrame: ..cellClass:\n"); - [super initWithFrame:frameRect]; + [super initWithFrame:frameRect]; - if (rowsHigh < 0) + if (rowsHigh < 0) { - NSLog(@"NSMatrix initWithFrame:mode: rows has to be >= 0.\n"); - NSLog(@"Will create matrix with 0 rows.\n"); - - num_rows = 0; + NSLog(@"NSMatrix initWithFrame:mode: rows has to be >= 0.\n"); + NSLog(@"Will create matrix with 0 rows.\n"); + + num_rows = 0; } - else + else { - num_rows = rowsHigh; + num_rows = rowsHigh; + } + + if (colsWide < 0) + { + NSLog(@"NSMatrix initWithFrame:mode: columns has to be >= 0.\n"); + NSLog(@"Will create matrix with 0 columns.\n"); + + num_cols = 0; + } + else + { + num_cols = colsWide; } - if (colsWide < 0) - { - NSLog(@"NSMatrix initWithFrame:mode: columns has to be >= 0.\n"); - NSLog(@"Will create matrix with 0 columns.\n"); - - num_cols = 0; - } - else - { - num_cols = colsWide; - } - - rows = [[NSMutableArray alloc] init]; - row_heights = [[NSMutableArray alloc] init]; - col_widths = [[NSMutableArray alloc] init]; - selected_cells = [[NSMutableArray alloc] init]; - inter_cell.width = inter_cell.height = 2; + rows = [[NSMutableArray alloc] init]; + row_heights = [[NSMutableArray alloc] init]; + col_widths = [[NSMutableArray alloc] init]; + selected_cells = [[NSMutableArray alloc] init]; + inter_cell.width = inter_cell.height = 2; + allows_empty_selection = YES; - cell_prototype = nil; - cell_class = classId; - mode = aMode; + cell_prototype = nil; + cell_class = classId; + mode = aMode; - [self createInitialMatrix]; + [self createInitialMatrix]; - NSDebugLog(@"NSMatrix end -initWithFrame: ..cellClass:\n"); - return self; + NSDebugLog(@"NSMatrix end -initWithFrame: ..cellClass:\n"); + return self; } - (id)initWithFrame:(NSRect)frameRect @@ -177,25 +181,25 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; numberOfRows:(int)rowsHigh numberOfColumns:(int)colsWide { - [super initWithFrame:frameRect]; + [super initWithFrame:frameRect]; - if (aCell == nil) + if (aCell == nil) { - NSLog(@"NSMatrix "); - NSLog(@"initWithFrame:mode:prototype:numberOfRows:numberOfColumns: "); - NSLog(@"prototype can't be nil. "); - NSLog(@"Using NSCell as the default class.\n"); + NSLog(@"NSMatrix "); + NSLog(@"initWithFrame:mode:prototype:numberOfRows:numberOfColumns: "); + NSLog(@"prototype can't be nil. "); + NSLog(@"Using NSCell as the default class.\n"); - cell_prototype = nil; + cell_prototype = nil; - cell_class = [NSCell class]; + cell_class = [NSCell class]; } - else + else { - cell_prototype = [aCell retain]; + cell_prototype = [aCell retain]; } - return self; + return self; } // @@ -208,7 +212,7 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (void)setMode:(NSMatrixMode)aMode { - mode = aMode; + mode = aMode; } // @@ -226,12 +230,12 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (void)setAllowsEmptySelection:(BOOL)flag { - allows_empty_selection = flag; + allows_empty_selection = flag; } - (void)setSelectionByRect:(BOOL)flag { - selection_by_rect = flag; + selection_by_rect = flag; } // @@ -249,12 +253,12 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (void)setCellClass:(Class)classId { - cell_class = classId; + cell_class = classId; } - (void)setPrototype:(NSCell *)aCell { - cell_prototype = [aCell retain]; + cell_prototype = [aCell retain]; } // @@ -262,9 +266,9 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; // - (void)addColumn { - int i; - NSNumber *anInt; - NSMutableArray *aRow; + int i; + NSNumber *anInt; + NSMutableArray *aRow; if (num_rows <= 0) { @@ -299,7 +303,61 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (void)addColumnWithCells:(NSArray *)cellArray { - [self insertColumn:num_cols withCells:cellArray]; + NSMutableArray *a; + id e, o; + id re, aRow; + int nrows, new_rows; + NSNumber *aFloat; + NSSize cs; + int i; + + NSDebugLog(@"NSMatrix addColumnWithCells:\n"); + + // No array then forget the add + if (!cellArray) + return; + + // Add more rows if need be + nrows = [cellArray count]; + if (nrows > num_rows) + { + NSDebugLog(@"NSMatrix add more rows %d %d\n", nrows, num_rows); + new_rows = nrows - num_rows; + for (i = 0; i < new_rows; ++i) + { + a = [[NSMutableArray alloc] init]; + [rows addObject: a]; + ++num_rows; + } + } + ++num_cols; + NSDebugLog(@"NSMatrix rows %d cols %d\n", num_rows, num_cols); + + // Determine cell width and height for uniform cell size + cs.width = (frame.size.width - (inter_cell.width * (num_cols - 1))) + / num_cols; + cs.height = (frame.size.height - (inter_cell.height * (num_rows - 1))) + / num_rows; + + // Save cell widths and heights in arrays + aFloat = [NSNumber numberWithFloat: cs.height]; + for (i = 0;i < nrows; ++i) + [row_heights addObject:aFloat]; + aFloat = [NSNumber numberWithFloat: cs.width]; + [col_widths addObject:aFloat]; + NSDebugLog(@"NSMatrix cell size %f %f\n", cs.width, cs.height); + + e = [cellArray objectEnumerator]; + o = [e nextObject]; + re = [rows objectEnumerator]; + aRow = [re nextObject]; + while (o) + { + [aRow addObject: o]; + [o retain]; + o = [e nextObject]; + aRow = [re nextObject]; + } } - (void)addRow @@ -346,7 +404,90 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (void)addRowWithCells:(NSArray *)cellArray { - [self insertRow:num_rows withCells:cellArray]; + NSMutableArray *a; + id e, o; + float ncols; + NSNumber *aFloat; + NSSize cs; + int i; + + NSDebugLog(@"NSMatrix addRowWithCells:\n"); + + // No array then forget the add + if (!cellArray) + return; + + a = [[NSMutableArray alloc] init]; + [rows addObject: a]; + ++num_rows; + ncols = [cellArray count]; + + // Determine cell width and height for uniform cell size + cs.width = (frame.size.width - (inter_cell.width * (ncols - 1))) + / ncols; + cs.height = (frame.size.height - (inter_cell.height * (num_rows - 1))) + / num_rows; + + // Save cell widths and heights in arrays + aFloat = [NSNumber numberWithFloat: cs.height]; + [row_heights addObject:aFloat]; + aFloat = [NSNumber numberWithFloat: cs.width]; + for (i = 0;i < ncols; ++i) + [col_widths addObject:aFloat]; + + e = [cellArray objectEnumerator]; + o = [e nextObject]; + while (o) + { + [a addObject: o]; + [o retain]; + o = [e nextObject]; + } +} + +- (void)addRowWithCells:(NSArray *)cellArray + rowSizes:(NSArray *)rowSizes + columnSizes:(NSArray *)columnSizes +{ + NSMutableArray *a; + id e, o; + float ncols; + NSNumber *aFloat; + NSSize cs; + int i; + + NSDebugLog(@"NSMatrix addRowWithCells:\n"); + + // No array then forget the insert + if (!cellArray) + return; + + a = [[NSMutableArray alloc] init]; + [rows addObject: a]; + ++num_rows; + ncols = [cellArray count]; + + // Determine cell width and height for uniform cell size + cs.width = (frame.size.width - (inter_cell.width * (ncols - 1))) + / ncols; + cs.height = (frame.size.height - (inter_cell.height * (num_rows - 1))) + / num_rows; + + // Save cell widths and heights in arrays + aFloat = [NSNumber numberWithFloat: cs.height]; + [row_heights addObject:aFloat]; + aFloat = [NSNumber numberWithFloat: cs.width]; + for (i = 0;i < ncols; ++i) + [col_widths addObject:aFloat]; + + e = [cellArray objectEnumerator]; + o = [e nextObject]; + while (o) + { + [a addObject: o]; + [o retain]; + o = [e nextObject]; + } } - (NSRect)cellFrameAtRow:(int)row @@ -361,6 +502,7 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; r.size.width = 0; r.size.height = 0; +#if 0 /* Validate arguments */ if ((row >= num_rows) || (row < 0)) { @@ -371,6 +513,7 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; { return r; } +#endif /* Compute the x origin */ for (i=0; i (myFrame.origin.x + myFrame.size.width)) - || (aPoint.y < myFrame.origin.y) - || (aPoint.y > (myFrame.origin.y + myFrame.size.height))) + if (![self mouse: aPoint inRect: myFrame]) { - NSDebugLog(@"NSMatrix point %f %f not in rect %f %f %f %f\n", - aPoint.x, aPoint.y, myFrame.origin.x, myFrame.origin.y, - myFrame.size.width, myFrame.size.height); - return NO; + NSDebugLog(@"NSMatrix point %f %f not in rect %f %f %f %f\n", + aPoint.x, aPoint.y, myFrame.origin.x, myFrame.origin.y, + myFrame.size.width, myFrame.size.height); + return NO; } - else - { - /* Here an optimized algo could be used at the expense of clarity */ - for (i=0; i= cFrame.origin.x) - && (aPoint.x <= (cFrame.origin.x + cFrame.size.width)) - && (aPoint.y >= cFrame.origin.y) - && (aPoint.y <= (cFrame.origin.y + cFrame.size.height))) - { - *row = i; - *column = j; - return YES; - } + if ([self mouse: aPoint inRect: cFrame]) + { + *row = i; + *column = j; + return YES; } + aCol = [ce nextObject]; + ++j; } - return NO; + aRow = [re nextObject]; + ++i; } + return NO; } - (BOOL)getRow:(int *)row column:(int *)column ofCell:(NSCell *)aCell { - int i, j; + id re, ce; + id aRow, aCol; + int i, j; - for (i=0; i 0) + // Only empty array if empty selection is allowed + if ((cnt != 1) || (allows_empty_selection)) + [selected_cells removeLastObject]; } - (void)selectAll:(id)sender @@ -802,17 +962,17 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (void)selectCellAtRow:(int)row column:(int)column { - int index; - id aCell = [self cellAtRow:row column:column]; + int index; + id aCell = [self cellAtRow:row column:column]; - NSDebugLog(@"NSMatrix select cell at %d %d\n", row, column); - if (aCell != nil) + NSDebugLog(@"NSMatrix select cell at %d %d\n", row, column); + if (aCell != nil) { - index = [selected_cells indexOfObject:aCell]; - - if ((index < 0) || (index > [selected_cells count])) + // Add to selected cell list if not already + index = [selected_cells indexOfObject:aCell]; + if ((index < 0) || (index > [selected_cells count])) { - [selected_cells addObject:aCell]; + [selected_cells addObject:aCell]; } } } @@ -838,7 +998,7 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (id)selectedCell { - return [selected_cells lastObject]; + return [selected_cells lastObject]; } /* @@ -851,66 +1011,42 @@ Class NSMATRIX_DEFAULT_CELL_CLASS; - (int)selectedColumn { - int row, col; - NSMutableArray *aRow, *aCol; - id aCell; - - if ([selected_cells count]) { + int row, col; + id aCell; - aCell = [selected_cells lastObject]; - - for (row=0; row 0) - { - aCell = [selected_cells lastObject]; - - for (row=0; row= num_rows) || (row < 0)) + id aRow; + + if ((row >= num_rows) || (row < 0)) { - NSLog(@"NSMatrix cellAt:: invalid row (%d)\n", row); - return nil; + NSLog(@"NSMatrix cellAt:: invalid row (%d)\n", row); + return nil; + } + aRow = [rows objectAtIndex: row]; + + if ((column >= [aRow count]) || (column < 0)) + { + NSLog(@"NSMatrix cellAt:: invalid column (%d)\n", column); + return nil; } - if ((column >= num_cols) || (column < 0)) - { - NSLog(@"NSMatrix cellAt:: invalid column (%d)\n", column); - return nil; - } - - return [(NSArray *)[rows objectAtIndex:row] objectAtIndex:column]; + return [(NSArray *)aRow objectAtIndex:column]; } - (id)cellWithTag:(int)anInt { - int i, j; - NSMutableArray *aRow; - NSCell *aCell; - - for (i=0; i #include #include +#include NSZone *gnustep_gui_nsmenu_zone = NULL; @@ -76,6 +77,8 @@ NSZone *gnustep_gui_nsmenu_zone = NULL; // Default initializer - (id)initWithTitle:(NSString *)aTitle { + NSApplication *theApp = [NSApplication sharedApplication]; + // Init our superclass but skip any of its backend implementation [super cleanInit]; @@ -83,9 +86,16 @@ NSZone *gnustep_gui_nsmenu_zone = NULL; menu_items = [NSMutableArray array]; super_menu = nil; autoenables_items = NO; - menu_matrix = nil; + // [self setContentView:[[NSView alloc] initWithFrame:frame]]; + menu_matrix = [[NSMatrix alloc] initWithFrame: NSZeroRect]; + [menu_matrix setCellClass: [NSMenuCell class]]; + [menu_matrix setIntercellSpacing: NSZeroSize]; + [self setContentView: menu_matrix]; is_torn_off = NO; + // Register ourselves with the Application object + [theApp addWindowsItem:self title:window_title filename:NO]; + return self; } diff --git a/Source/NSWindow.m b/Source/NSWindow.m index cc13a479e..277e3e433 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -39,20 +39,20 @@ #include // NSWindow notifications -NSString *NSWindowDidBecomeKeyNotification; -NSString *NSWindowDidBecomeMainNotification; -NSString *NSWindowDidChangeScreenNotification; -NSString *NSWindowDidDeminiaturizeNotification; -NSString *NSWindowDidExposeNotification; -NSString *NSWindowDidMiniaturizeNotification; -NSString *NSWindowDidMoveNotification; -NSString *NSWindowDidResignKeyNotification; -NSString *NSWindowDidResignMainNotification; -NSString *NSWindowDidResizeNotification; -NSString *NSWindowDidUpdateNotification; -NSString *NSWindowWillCloseNotification; -NSString *NSWindowWillMiniaturizeNotification; -NSString *NSWindowWillMoveNotification; +NSString *NSWindowDidBecomeKeyNotification = @"WindowDidBecomeKey"; +NSString *NSWindowDidBecomeMainNotification = @"WindowDidBecomeMain"; +NSString *NSWindowDidChangeScreenNotification = @"WindowDidChangeScreen"; +NSString *NSWindowDidDeminiaturizeNotification = @"WindowDidDeminiaturize"; +NSString *NSWindowDidExposeNotification = @"WindowDidExpose"; +NSString *NSWindowDidMiniaturizeNotification = @"WindowDidMiniaturize"; +NSString *NSWindowDidMoveNotification = @"WindowDidMove"; +NSString *NSWindowDidResignKeyNotification = @"WindowDidResignKey"; +NSString *NSWindowDidResignMainNotification = @"WindowDidResignMain"; +NSString *NSWindowDidResizeNotification = @"WindowDidResize"; +NSString *NSWindowDidUpdateNotification = @"WindowDidUpdate"; +NSString *NSWindowWillCloseNotification = @"WindowWillClose"; +NSString *NSWindowWillMiniaturizeNotification = @"WindowWillMiniaturize"; +NSString *NSWindowWillMoveNotification = @"WindowWillMove"; // // NSWindow implementation @@ -82,15 +82,13 @@ NSString *NSWindowWillMoveNotification; + (NSRect)contentRectForFrameRect:(NSRect)aRect styleMask:(unsigned int)aStyle { - NSRect t; - return t; + return aRect; } + (NSRect)frameRectForContentRect:(NSRect)aRect styleMask:(unsigned int)aStyle { - NSRect t; - return t; + return aRect; } + (NSRect)minFrameWidthWithTitle:(NSString *)aTitle @@ -103,7 +101,7 @@ NSString *NSWindowWillMoveNotification; // Screens and window depths + (NSWindowDepth)defaultDepthLimit { - return 0; + return 8; } // @@ -159,39 +157,30 @@ NSString *NSWindowWillMoveNotification; screen:aScreen { NSApplication *theApp = [NSApplication sharedApplication]; + NSRect r = [[NSScreen mainScreen] frame]; NSDebugLog(@"NSWindow default initializer\n"); if (!theApp) NSLog(@"No application!\n"); - [super init]; - NSDebugLog(@"NSWindow start of init\n"); - frame = contentRect; + // Initialize attributes and flags + [self cleanInit]; + + backing_type = bufferingType; style_mask = aStyle; + // Size attributes + frame = [NSWindow frameRectForContentRect: contentRect styleMask: aStyle]; + minimum_size = NSZeroSize; + maximum_size = r.size; + // Next responder is the application [self setNextResponder:theApp]; - // Initialize attributes and flags - frame_view = nil; + // Create our content view [self setContentView:[[NSView alloc] initWithFrame:frame]]; - first_responder = nil; - delegate = nil; - window_num = 0; - background_color = [NSColor lightGrayColor]; - represented_filename = @"Window"; - miniaturized_title = @"Window"; - window_title = @"Window"; - visible = NO; - is_key = NO; - is_main = NO; - is_edited = NO; - is_miniaturized = NO; - menu_exclude = NO; - backing_type = bufferingType; - disable_flush_window = NO; // Register ourselves with the Application object [theApp addWindowsItem:self title:window_title filename:NO]; @@ -294,7 +283,7 @@ NSString *NSWindowWillMoveNotification; - (BOOL)isOneShot { - return NO; + return is_one_shot; } - (void)setBackingType:(NSBackingStoreType)type @@ -303,7 +292,9 @@ NSString *NSWindowWillMoveNotification; } - (void)setOneShot:(BOOL)flag -{} +{ + is_one_shot = flag; +} - (int)windowNumber { @@ -320,7 +311,7 @@ NSString *NSWindowWillMoveNotification; // - (NSImage *)miniwindowImage { - return nil; + return miniaturized_image; } - (NSString *)miniwindowTitle @@ -329,7 +320,9 @@ NSString *NSWindowWillMoveNotification; } - (void)setMiniwindowImage:(NSImage *)image -{} +{ + miniaturized_image = image; +} - (void)setMiniwindowTitle:(NSString *)title; { @@ -353,20 +346,24 @@ NSString *NSWindowWillMoveNotification; // - (void)becomeKeyWindow { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // We are the key window is_key = YES; // Post notification - [self windowDidBecomeKey:self]; + [nc postNotificationName: NSWindowDidBecomeKeyNotification object: self]; } - (void)becomeMainWindow { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // We are the main window is_main = YES; // Post notification - [self windowDidBecomeMain:self]; + [nc postNotificationName: NSWindowDidBecomeMainNotification object: self]; } - (BOOL)canBecomeKeyWindow @@ -381,7 +378,7 @@ NSString *NSWindowWillMoveNotification; - (BOOL)hidesOnDeactivate { - return NO; + return hides_on_deactivate; } - (BOOL)isKeyWindow @@ -406,7 +403,7 @@ NSString *NSWindowWillMoveNotification; - (int)level { - return 0; + return window_level; } - (void)makeKeyAndOrderFront:sender @@ -472,25 +469,33 @@ NSString *NSWindowWillMoveNotification; - (void)resignKeyWindow { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + is_key = NO; // Post notification - [self windowDidResignKey: self]; + [nc postNotificationName: NSWindowDidResignKeyNotification object: self]; } - (void)resignMainWindow { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + is_main = NO; // Post notification - [self windowDidResignMain: self]; + [nc postNotificationName: NSWindowDidResignMainNotification object: self]; } - (void)setHidesOnDeactivate:(BOOL)flag -{} +{ + hides_on_deactivate = flag; +} - (void)setLevel:(int)newLevel -{} +{ + window_level = newLevel; +} // // Moving and resizing the window @@ -527,12 +532,12 @@ NSString *NSWindowWillMoveNotification; - (NSSize)minSize { - return NSZeroSize; + return minimum_size; } - (NSSize)maxSize { - return NSZeroSize; + return maximum_size; } - (void)setContentSize:(NSSize)aSize @@ -542,23 +547,35 @@ NSString *NSWindowWillMoveNotification; - (void)setFrame:(NSRect)frameRect display:(BOOL)flag { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + frame = frameRect; + // post notification + [nc postNotificationName: NSWindowDidResizeNotification object: self]; + + // display if requested if (!flag) return; [self display]; } - (void)setFrameOrigin:(NSPoint)aPoint -{} +{ + frame.origin = aPoint; +} - (void)setFrameTopLeftPoint:(NSPoint)aPoint {} - (void)setMinSize:(NSSize)aSize -{} +{ + minimum_size = aSize; +} - (void)setMaxSize:(NSSize)aSize -{} +{ + maximum_size = aSize; +} // // Converting coordinates @@ -592,7 +609,10 @@ NSString *NSWindowWillMoveNotification; } - (void)displayIfNeeded -{} +{ + if (needs_display) + [self display]; +} - (void)enableFlushWindow { @@ -603,39 +623,56 @@ NSString *NSWindowWillMoveNotification; {} - (void)flushWindowIfNeeded -{} +{ + if (!disable_flush_window) + [self flushWindow]; +} - (BOOL)isAutodisplay { - return YES; + return is_autodisplay; } - (BOOL)isFlushWindowDisabled { - return NO; + return disable_flush_window; } - (void)setAutoDisplay:(BOOL)flag -{} +{ + is_autodisplay = flag; +} - (void)setViewsNeedDisplay:(BOOL)flag -{} +{ + views_need_display = flag; +} - (void)update -{} +{ + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + + [nc postNotificationName: NSWindowDidUpdateNotification object: self]; +} - (void)useOptimizedDrawing:(BOOL)flag -{} +{ + optimize_drawing = flag; +} - (BOOL)viewsNeedDisplay { - return NO; + return views_need_display; } // Screens and window depths - (BOOL)canStoreColor { - return YES; + // If the depth is greater than a single bit + if (depth_limit > 1) + return YES; + else + return NO; } - (NSScreen *)deepestScreen @@ -645,12 +682,12 @@ NSString *NSWindowWillMoveNotification; - (NSWindowDepth)depthLimit { - return 0; + return depth_limit; } - (BOOL)hasDynamicDepthLimit { - return YES; + return dynamic_depth_limit; } - (NSScreen *)screen @@ -659,27 +696,35 @@ NSString *NSWindowWillMoveNotification; } - (void)setDepthLimit:(NSWindowDepth)limit -{} +{ + depth_limit = limit; +} - (void)setDynamicDepthLimit:(BOOL)flag -{} +{ + dynamic_depth_limit = flag; +} // // Cursor management // - (BOOL)areCursorRectsEnabled { - return NO; + return cursor_rects_enabled; } - (void)disableCursorRects -{} +{ + cursor_rects_enabled = NO; +} - (void)discardCursorRects {} - (void)enableCursorRects -{} +{ + cursor_rects_enabled = YES; +} - (void)invalidateCursorRectsForView:(NSView *)aView {} @@ -692,20 +737,24 @@ NSString *NSWindowWillMoveNotification; // - (void)close { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // Notify our delegate - [self windowWillClose:self]; + [nc postNotificationName: NSWindowWillCloseNotification object: self]; [self performClose:self]; } - (void)deminiaturize:sender { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // Set our flag to say we are not miniaturized is_miniaturized = NO; visible = YES; // Notify our delegate - [self windowDidDeminiaturize:self]; + [nc postNotificationName: NSWindowDidDeminiaturizeNotification object: self]; } - (BOOL)isDocumentEdited @@ -715,18 +764,20 @@ NSString *NSWindowWillMoveNotification; - (BOOL)isReleasedWhenClosed { - return YES; + return is_released_when_closed; } - (void)miniaturize:sender { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + // Notify our delegate - [self windowWillMiniaturize:self]; + [nc postNotificationName: NSWindowWillMiniaturizeNotification object: self]; [self performMiniaturize:self]; // Notify our delegate - [self windowDidMiniaturize:self]; + [nc postNotificationName: NSWindowDidMiniaturizeNotification object: self]; } - (void)performClose:sender @@ -746,17 +797,21 @@ NSString *NSWindowWillMoveNotification; } - (void)setDocumentEdited:(BOOL)flag -{} +{ + is_edited = flag; +} - (void)setReleasedWhenClosed:(BOOL)flag -{} +{ + is_released_when_closed = flag; +} // // Aiding event handling // - (BOOL)acceptsMouseMovedEvents { - return YES; + return accepts_mouse_moved; } - (NSEvent *)currentEvent @@ -768,7 +823,11 @@ NSString *NSWindowWillMoveNotification; - (void)discardEventsMatchingMask:(unsigned int)mask beforeEvent:(NSEvent *)lastEvent -{} +{ + NSApplication *theApp = [NSApplication sharedApplication]; + + [theApp discardEventsMatchingMask: mask beforeEvent: lastEvent]; +} - (NSResponder *)firstResponder { @@ -821,7 +880,9 @@ NSString *NSWindowWillMoveNotification; - (NSEvent *)nextEventMatchingMask:(unsigned int)mask { - return nil; + NSApplication *theApp = [NSApplication sharedApplication]; + return [theApp nextEventMatchingMask: mask untilDate: nil + inMode: @"" dequeue: YES]; } - (NSEvent *)nextEventMatchingMask:(unsigned int)mask @@ -829,7 +890,9 @@ NSString *NSWindowWillMoveNotification; inMode:(NSString *)mode dequeue:(BOOL)deqFlag { - return nil; + NSApplication *theApp = [NSApplication sharedApplication]; + return [theApp nextEventMatchingMask: mask untilDate: expiration + inMode: mode dequeue: deqFlag]; } - (void)postEvent:(NSEvent *)event @@ -841,7 +904,9 @@ NSString *NSWindowWillMoveNotification; } - (void)setAcceptsMouseMovedEvents:(BOOL)flag -{} +{ + accepts_mouse_moved = flag; +} - (void)checkTrackingRectangles:(NSView *)theView forEvent:(NSEvent *)theEvent { @@ -1044,7 +1109,7 @@ NSString *NSWindowWillMoveNotification; - (BOOL)worksWhenModal { - return YES; + return NO; } // @@ -1116,7 +1181,7 @@ NSString *NSWindowWillMoveNotification; // // Printing and postscript // -- (NSDate *)dataWithEPSInsideRect:(NSRect)rect +- (NSData *)dataWithEPSInsideRect:(NSRect)rect { return nil; } @@ -1319,9 +1384,12 @@ NSString *NSWindowWillMoveNotification; return self; } +@end + // -// GNUstep additional methods +// GNUstep backend methods // +@implementation NSWindow (GNUstepBackend) // // Mouse capture/release @@ -1338,9 +1406,45 @@ NSString *NSWindowWillMoveNotification; // Allow subclasses to init without the backend class // attempting to create an actual window +- (void)initDefaults +{ + first_responder = nil; + original_responder = nil; + delegate = nil; + window_num = 0; + background_color = [NSColor lightGrayColor]; + represented_filename = @"Window"; + miniaturized_title = @"Window"; + miniaturized_image = nil; + window_title = @"Window"; + last_point = NSZeroPoint; + window_level = NSNormalWindowLevel; + + is_one_shot = NO; + needs_display = NO; + is_autodisplay = YES; + optimize_drawing = YES; + views_need_display = NO; + depth_limit = 8; + dynamic_depth_limit = YES; + cursor_rects_enabled = NO; + visible = NO; + is_key = NO; + is_main = NO; + is_edited = NO; + is_released_when_closed = NO; + is_miniaturized = NO; + disable_flush_window = NO; + menu_exclude = NO; + hides_on_deactivate = NO; + accepts_mouse_moved = YES; +} + - cleanInit { [super init]; + + [self initDefaults]; return self; }