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
This commit is contained in:
Scott Christley 1996-10-03 18:45:41 +00:00
parent 4f871af2e9
commit acc25ab0e2
6 changed files with 725 additions and 412 deletions

View file

@ -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;
}
}

View file

@ -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<column; i++)
@ -383,14 +526,16 @@ Class NSMATRIX_DEFAULT_CELL_CLASS;
r.size.width = [(NSNumber *)[col_widths objectAtIndex:i] floatValue];
/* Compute the y origin */
for (i=0; i<row; i++)
r.origin.y = frame.size.height;
r.origin.y -= [(NSNumber *)[row_heights objectAtIndex:0] floatValue];
for (i = 1;i < (row+1); i++)
{
r.origin.y += [(NSNumber *)[row_heights objectAtIndex:i] floatValue];
r.origin.y += inter_cell.height;
r.origin.y -= inter_cell.height;
r.origin.y -= [(NSNumber *)[row_heights objectAtIndex:i] floatValue];
}
/* Get the height */
r.size.height = [(NSNumber *)[row_heights objectAtIndex:i] floatValue];
r.size.height = [(NSNumber *)[row_heights objectAtIndex:row] floatValue];
NSDebugLog(@"NSMatrix cellFrameAtRow: %d column:%d is: %f %f %f %f\n",
row, column,
@ -513,32 +658,24 @@ Class NSMATRIX_DEFAULT_CELL_CLASS;
- (void)insertRow:(int)row withCells:(NSArray *)cellArray
{
NSCell *newCell;
int i, count;
NSCell *newCell;
int i, count;
id e, o;
[self insertRow:row];
// No array then forget the insert
if (!cellArray)
return;
if (cellArray != nil)
[self insertRow:row];
e = [cellArray objectEnumerator];
o = [e nextObject];
i = 0;
while (o)
{
count = [cellArray count];
}
else
{
count = 0;
}
for (i=0; i<num_cols; i++)
{
if (i < count)
{
newCell = (NSCell *)[cellArray objectAtIndex:i];
[self putCell:newCell atRow:row column:i];
}
else
{
break;
}
[self putCell: o atRow: row column: i];
o = [e nextObject];
++i;
}
}
@ -697,66 +834,82 @@ Class NSMATRIX_DEFAULT_CELL_CLASS;
column:(int *)column
forPoint:(NSPoint)aPoint
{
NSRect myFrame = [self bounds];
NSRect cFrame;
int i, j;
NSRect myFrame = [self bounds];
NSRect cFrame;
id re, ce;
id aRow, aCol;
int i, j;
/* Trivial rejection if the point is not in the Matrix's frame rect */
/* Trivial rejection if the point is not in the Matrix's frame rect */
if ((aPoint.x < myFrame.origin.x)
|| (aPoint.x > (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<num_rows; i++)
/* Here an optimized algo could be used at the expense of clarity */
re = [rows objectEnumerator];
aRow = [re nextObject];
i = 0;
while (aRow)
{
ce = [aRow objectEnumerator];
aCol = [ce nextObject];
j = 0;
while (aCol)
{
for (j=0; j<num_cols; j++)
{
cFrame = [self cellFrameAtRow:i column:j];
cFrame = [self cellFrameAtRow:i column:j];
if ((aPoint.x >= 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<num_rows; i++)
re = [rows objectEnumerator];
aRow = [re nextObject];
i = 0;
while (aRow)
{
for (j=0; j<num_cols; j++)
ce = [aRow objectEnumerator];
aCol = [ce nextObject];
j = 0;
while (aCol)
{
if ((NSCell *)[self cellAtRow:i column:j] == aCell)
if ((NSCell *)[self cellAtRow:i column:j] == aCell)
{
*row = i;
*column = j;
return YES;
*row = i;
*column = j;
return YES;
}
aCol = [ce nextObject];
++j;
}
aRow = [re nextObject];
++i;
}
return NO;
return NO;
}
//
@ -785,12 +938,19 @@ Class NSMATRIX_DEFAULT_CELL_CLASS;
//
- (void)deselectAllCells
{
if (allows_empty_selection)
[selected_cells removeAllObjects];
}
- (void)deselectSelectedCell
{
[selected_cells removeLastObject];
int cnt = [selected_cells count];
// Is anything even selected?
if (cnt > 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<num_rows; row++)
{
aRow = [rows objectAtIndex:row];
if ([selected_cells count])
{
aCell = [selected_cells lastObject];
for (col=0; col<num_cols; col++)
{
aCol = [aRow objectAtIndex:col];
if ([aCol indexOfObject:aCell] < num_cols)
{
return col;
}
}
}
if ([self getRow: &row column: &col ofCell: aCell])
return col;
}
return -1; /* not found */
// Not found
return -1;
}
- (int)selectedRow
{
int row, col;
NSMutableArray *aRow, *aCol;
id aCell;
if ([selected_cells count] > 0)
{
aCell = [selected_cells lastObject];
for (row=0; row<num_rows; row++)
{
aRow = [rows objectAtIndex:row];
int row, col;
id aCell;
for (col=0; col<num_cols; col++)
{
aCol = [aRow objectAtIndex:col];
if ([aCol indexOfObject:aCell] < num_cols)
{
return row;
}
}
}
if ([selected_cells count])
{
aCell = [selected_cells lastObject];
if ([self getRow: &row column: &col ofCell: aCell])
return row;
}
return -1; /* not found */
// Not found
return -1;
}
- (void)setSelectionFrom:(int)startPos
to:(int)endPos
anchor:(int)anchorPos
highlight:(BOOL)flag
highlight:(BOOL)flag
{}
//
@ -919,42 +1055,46 @@ Class NSMATRIX_DEFAULT_CELL_CLASS;
- (id)cellAtRow:(int)row
column:(int)column
{
if ((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<num_rows; i++)
{
aRow = (NSMutableArray *)[rows objectAtIndex:i];
id re, ce;
int i, j;
NSMutableArray *aRow;
NSCell *aCell;
for (j=0; j<num_cols; j++)
// Loop through the rows and columns and find the cell
re = [rows objectEnumerator];
aRow = [re nextObject];
while (aRow)
{
ce = [aRow objectEnumerator];
aCell = (NSCell *)[ce nextObject];
while (aCell)
{
aCell = [aRow objectAtIndex:j];
if ([aCell tag] == anInt)
{
return (id)aCell;
}
if ([aCell tag] == anInt)
return aCell;
aCell = (NSCell *)[ce nextObject];
}
}
return nil;
return nil;
}
- (NSArray *)cells
@ -1171,54 +1311,60 @@ Class NSMATRIX_DEFAULT_CELL_CLASS;
//
- (void)display;
{
int row,col;
int rcnt, ccnt;
NSMutableArray *aRow;
id re, ce;
int row, col;
NSMutableArray *aRow;
id aCol;
NSDebugLog(@"NSMatrix display\n");
rcnt = [rows count];
if (rcnt != num_rows)
NSLog(@"NSMatrix internal error: num_rows != actual rows\n");
NSDebugLog(@"NSMatrix display %f %f %f %f\n", bounds.origin.x,
bounds.origin.y, bounds.size.width, bounds.size.height);
for (row=0; row<rcnt; row++)
re = [rows objectEnumerator];
aRow = (NSMutableArray *)[re nextObject];
row = 0;
while (aRow)
{
aRow = [rows objectAtIndex:row];
ccnt = [aRow count];
if (ccnt != num_cols)
NSLog(@"NSMatrix internal error: num_cols != actual columns\n");
for (col=0; col<ccnt; col++)
ce = [aRow objectEnumerator];
aCol = [ce nextObject];
col = 0;
while (aCol)
{
[self drawCellAtRow: row column: col];
[self drawCellAtRow: row column: col];
++col;
aCol = [ce nextObject];
}
++row;
aRow = [re nextObject];
}
NSDebugLog(@"End NSMatrix display\n");
NSDebugLog(@"End NSMatrix display\n");
}
- (void)drawCellAtRow:(int)row
column:(int)column
{
NSMutableArray *aRow = [rows objectAtIndex: row];
NSMutableArray *aRow = [rows objectAtIndex: row];
NSCell *aCell = [aRow objectAtIndex: column];
[[aRow objectAtIndex:column] drawWithFrame:
[self cellFrameAtRow:row column:column]
inView:self];
NSDebugLog(@"NSMatrix draw cell %d %d %d %d\n", row, column, [rows count],
[aRow count]);
[aCell drawWithFrame:
[self cellFrameAtRow:row column:column]
inView:self];
}
- (void)highlightCell:(BOOL)flag
atRow:(int)row
column:(int)column
{
NSCell *aCell = [self cellAtRow:row column:column];
NSRect cellFrame;
NSCell *aCell = [self cellAtRow:row column:column];
NSRect cellFrame;
BOOL did_lock = NO;
if (aCell != nil)
if (aCell != nil)
{
cellFrame = [self cellFrameAtRow:row column:column];
[aCell highlight:flag withFrame:cellFrame inView:self];
cellFrame = [self cellFrameAtRow:row column:column];
[aCell highlight:flag withFrame:cellFrame inView:self];
}
}
//

View file

@ -32,6 +32,7 @@
#include <gnustep/gui/NSMenuPrivate.h>
#include <Foundation/NSLock.h>
#include <gnustep/base/NSCoder.h>
#include <gnustep/gui/NSApplication.h>
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;
}

View file

@ -39,20 +39,20 @@
#include <gnustep/base/NSCoder.h>
// 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;
}