Diverse gui patches by Wolfgang Lux <wolfgang.lux@gmail.com>.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25451 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-09-04 23:29:05 +00:00
parent 347b646c1d
commit 9a371e74bd
4 changed files with 165 additions and 126 deletions

View file

@ -1582,30 +1582,31 @@ void NSBeginInformationalAlertSheet(NSString *title,
{ {
GSAlertPanel *panel; GSAlertPanel *panel;
NSString *title; NSString *title;
unsigned nbut = [_buttons count];
panel = [[GSAlertPanel alloc] init]; panel = [[GSAlertPanel alloc] init];
_window = panel; _window = panel;
switch (_style) switch (_style)
{ {
case NSCriticalAlertStyle: case NSCriticalAlertStyle:
title = @"Critical"; title = @"Critical";
break; break;
case NSInformationalAlertStyle: case NSInformationalAlertStyle:
title = @"Information"; title = @"Information";
break; break;
case NSWarningAlertStyle: case NSWarningAlertStyle:
default: default:
title = @"Alert"; title = @"Alert";
break; break;
} }
[panel setTitleBar: title [panel setTitleBar: title
icon: _icon icon: _icon
title: _informative_text title: _informative_text
message: _message_text message: _message_text
def: [[_buttons objectAtIndex: 0] title] def: (nbut > 0) ? [[_buttons objectAtIndex: 0] title] : (NSString*)nil
alt: [[_buttons objectAtIndex: 1] title] alt: (nbut > 1) ? [[_buttons objectAtIndex: 1] title] : (NSString*)nil
other: [[_buttons objectAtIndex: 2] title]]; other: (nbut > 2) ? [[_buttons objectAtIndex: 2] title] : (NSString*)nil];
} }
} }

View file

@ -147,17 +147,17 @@ withContentsOfURL: (NSURL *)url
{ {
if ([self readFromURL: url if ([self readFromURL: url
ofType: type ofType: type
error: error]) error: error])
{ {
if (forUrl != nil) if (forUrl != nil)
{ {
[self setFileURL: forUrl]; [self setFileURL: forUrl];
} }
} }
else else
{ {
DESTROY(self); DESTROY(self);
} }
} }
return self; return self;
} }
@ -233,7 +233,12 @@ withContentsOfURL: (NSURL *)url
{ {
[self setFileURL: [NSURL fileURLWithPath: fileName]]; [self setFileURL: [NSURL fileURLWithPath: fileName]];
} }
ASSIGN(_file_name, fileName); else
{
ASSIGN(_file_name, fileName);
ASSIGN(_file_url, [NSURL fileURLWithPath: fileName]);
[self setLastComponentOfFileName: [_file_name lastPathComponent]];
}
[self setLastComponentOfFileName: [_file_name lastPathComponent]]; [self setLastComponentOfFileName: [_file_name lastPathComponent]];
} }
@ -269,6 +274,7 @@ withContentsOfURL: (NSURL *)url
else else
{ {
ASSIGN(_file_url, url); ASSIGN(_file_url, url);
ASSIGN(_file_name, (url && [url isFileURL]) ? [url path] : (NSString*)nil);
[self setLastComponentOfFileName: [[_file_url path] lastPathComponent]]; [self setLastComponentOfFileName: [[_file_url path] lastPathComponent]];
} }
} }
@ -537,6 +543,7 @@ withContentsOfURL: (NSURL *)url
{ {
if (OVERRIDDEN(dataRepresentationOfType:)) if (OVERRIDDEN(dataRepresentationOfType:))
{ {
*error = nil;
return [self dataRepresentationOfType: type]; return [self dataRepresentationOfType: type];
} }
@ -569,6 +576,7 @@ withContentsOfURL: (NSURL *)url
if (OVERRIDDEN(fileWrapperRepresentationOfType:)) if (OVERRIDDEN(fileWrapperRepresentationOfType:))
{ {
*error = nil;
return [self fileWrapperRepresentationOfType: type]; return [self fileWrapperRepresentationOfType: type];
} }
@ -654,6 +662,7 @@ withContentsOfURL: (NSURL *)url
{ {
if (OVERRIDDEN(loadFileWrapperRepresentation:ofType:)) if (OVERRIDDEN(loadFileWrapperRepresentation:ofType:))
{ {
*error = nil;
return [self loadFileWrapperRepresentation: wrapper ofType: type]; return [self loadFileWrapperRepresentation: wrapper ofType: type];
} }
@ -665,6 +674,7 @@ withContentsOfURL: (NSURL *)url
} }
// FIXME: Set error // FIXME: Set error
*error = nil;
return NO; return NO;
} }
@ -678,8 +688,9 @@ withContentsOfURL: (NSURL *)url
if (OVERRIDDEN(readFromFile:ofType:)) if (OVERRIDDEN(readFromFile:ofType:))
{ {
return [self readFromFile: [url path] ofType: type]; *error = nil;
} return [self readFromFile: [url path] ofType: type];
}
else else
{ {
NSFileWrapper *wrapper = AUTORELEASE([[NSFileWrapper alloc] initWithPath: fileName]); NSFileWrapper *wrapper = AUTORELEASE([[NSFileWrapper alloc] initWithPath: fileName]);
@ -691,6 +702,7 @@ withContentsOfURL: (NSURL *)url
} }
// FIXME: Set error // FIXME: Set error
*error = nil;
return NO; return NO;
} }
@ -817,17 +829,20 @@ withContentsOfURL: (NSURL *)url
if (OVERRIDDEN(writeWithBackupToFile:ofType:saveOperation:)) if (OVERRIDDEN(writeWithBackupToFile:ofType:saveOperation:))
{ {
if (saveOp == NSAutosaveOperation) if (saveOp == NSAutosaveOperation)
{ {
saveOp = NSSaveToOperation; saveOp = NSSaveToOperation;
} }
*error = nil;
return [self writeWithBackupToFile: [url path] return [self writeWithBackupToFile: [url path]
ofType: type ofType: type
saveOperation: saveOp]; saveOperation: saveOp];
} }
if (!isNativeType || (url == nil)) if (!isNativeType || (url == nil))
{ {
// FIXME: Set error
*error = nil;
return NO; return NO;
} }
@ -835,21 +850,22 @@ withContentsOfURL: (NSURL *)url
{ {
if ([url isFileURL]) if ([url isFileURL])
{ {
NSString *newFileName; NSString *newFileName;
newFileName = [url path]; newFileName = [url path];
if ([fileManager fileExistsAtPath: newFileName]) if ([fileManager fileExistsAtPath: newFileName])
{ {
backupFilename = [self _backupFileNameFor: newFileName]; backupFilename = [self _backupFileNameFor: newFileName];
if (![self _writeBackupForFile: newFileName if (![self _writeBackupForFile: newFileName
toFile: backupFilename]) toFile: backupFilename])
{ {
// FIXME: Set error. // FIXME: Set error.
return NO; *error = nil;
} return NO;
} }
} }
}
} }
if (![self writeToURL: url if (![self writeToURL: url
@ -891,16 +907,20 @@ withContentsOfURL: (NSURL *)url
if (OVERRIDDEN(writeToFile:ofType:)) if (OVERRIDDEN(writeToFile:ofType:))
{ {
return [self writeToFile: [url path] ofType: type]; *error = nil;
return [self writeToFile: [url path] ofType: type];
} }
wrapper = [self fileWrapperOfType: type wrapper = [self fileWrapperOfType: type
error: error]; error: error];
if (wrapper == nil) if (wrapper == nil)
{ {
// FIXME: Set error
*error = nil;
return NO; return NO;
} }
*error = nil;
return [wrapper writeToFile: [url path] atomically: YES updateFilenames: YES]; return [wrapper writeToFile: [url path] atomically: YES updateFilenames: YES];
} }
@ -913,9 +933,10 @@ originalContentsURL: (NSURL *)orig
if (OVERRIDDEN(writeToFile:ofType:originalFile:saveOperation:)) if (OVERRIDDEN(writeToFile:ofType:originalFile:saveOperation:))
{ {
if (saveOp == NSAutosaveOperation) if (saveOp == NSAutosaveOperation)
{ {
saveOp = NSSaveToOperation; *error = nil;
} saveOp = NSSaveToOperation;
}
return [self writeToFile: [url path] return [self writeToFile: [url path]
ofType: type ofType: type
@ -954,9 +975,9 @@ originalContentsURL: (NSURL *)orig
} }
- (void)runModalSavePanelForSaveOperation: (NSSaveOperationType)saveOperation - (void)runModalSavePanelForSaveOperation: (NSSaveOperationType)saveOperation
delegate: (id)delegate delegate: (id)delegate
didSaveSelector: (SEL)didSaveSelector didSaveSelector: (SEL)didSaveSelector
contextInfo: (void *)contextInfo contextInfo: (void *)contextInfo
{ {
NSString *fileName; NSString *fileName;
@ -1249,6 +1270,7 @@ originalContentsURL: (NSURL *)orig
- (NSPrintOperation *)printOperationWithSettings: (NSDictionary *)settings - (NSPrintOperation *)printOperationWithSettings: (NSDictionary *)settings
error: (NSError **)error error: (NSError **)error
{ {
*error = nil;
return nil; return nil;
} }
@ -1363,6 +1385,7 @@ originalContentsURL: (NSURL *)orig
error:(NSError **)error error:(NSError **)error
{ {
// FIXME: Implement. Should set NSFileExtensionHidden // FIXME: Implement. Should set NSFileExtensionHidden
*error = nil;
return [NSDictionary dictionary]; return [NSDictionary dictionary];
} }
@ -1483,7 +1506,7 @@ originalContentsURL: (NSURL *)orig
meth = (void (*)(id, SEL, id, BOOL, void*))[delegate methodForSelector: meth = (void (*)(id, SEL, id, BOOL, void*))[delegate methodForSelector:
didSaveSelector]; didSaveSelector];
if (meth) if (meth)
meth(delegate, didSaveSelector, self, saved, contextInfo); meth(delegate, didSaveSelector, self, saved, contextInfo);
} }
return saved; return saved;
@ -1501,18 +1524,18 @@ originalContentsURL: (NSURL *)orig
[self displayName]); [self displayName]);
if (result == NSAlertDefaultReturn) if (result == NSAlertDefaultReturn)
{ {
if ([self revertToContentsOfURL: [self fileURL] if ([self revertToContentsOfURL: [self fileURL]
ofType: [self fileType] ofType: [self fileType]
error: &error]) error: &error])
{ {
[self updateChangeCount: NSChangeCleared]; [self updateChangeCount: NSChangeCleared];
} }
else else
{ {
[self presentError: error]; [self presentError: error];
} }
} }
} }
/** Closes all the windows owned by the document, then removes itself /** Closes all the windows owned by the document, then removes itself

View file

@ -610,28 +610,28 @@ anything visible
{ {
/* The point is inside a rect; we're done. */ /* The point is inside a rect; we're done. */
if (NSPointInRect(point, lf->rect)) if (NSPointInRect(point, lf->rect))
break; break;
/* If the current line frag rect is below the point, the point must /* If the current line frag rect is below the point, the point must
be between the line with the current line frag rect and the line be between the line with the current line frag rect and the line
with the previous line frag rect. */ with the previous line frag rect. */
if (NSMinY(lf->rect) > point.y) if (NSMinY(lf->rect) > point.y)
{ {
/* If this is not the first line frag rect in the text container, /* If this is not the first line frag rect in the text container,
we consider the point to be after the last glyph on the previous we consider the point to be after the last glyph on the previous
line. Otherwise, we consider it to be before the first glyph on line. Otherwise, we consider it to be before the first glyph on
the current line. */ the current line. */
if (i > 0) if (i > 0)
{ {
*partialFraction = 1.0; *partialFraction = 1.0;
return lf->pos - 1; return lf->pos - 1;
} }
else else
{ {
*partialFraction = 0.0; *partialFraction = 0.0;
return lf->pos; return lf->pos;
} }
} }
/* We know that NSMinY(lf->rect) <= point.y. If the point is on the /* We know that NSMinY(lf->rect) <= point.y. If the point is on the
current line and to the left of the current line frag rect, we current line and to the left of the current line frag rect, we
consider the point to be before the first glyph in the current line consider the point to be before the first glyph in the current line
@ -646,10 +646,10 @@ anything visible
two lines' case, or by the 'after all line frags' code below.) two lines' case, or by the 'after all line frags' code below.)
*/ */
if (NSMaxY(lf->rect) >= point.y && NSMinX(lf->rect) > point.x) if (NSMaxY(lf->rect) >= point.y && NSMinX(lf->rect) > point.x)
{ {
*partialFraction = 0.0; *partialFraction = 0.0;
return lf->pos; return lf->pos;
} }
} }
/* Point is after all line frags. */ /* Point is after all line frags. */
@ -684,9 +684,9 @@ anything visible
unsigned j; unsigned j;
if (i < lf->num_points) if (i < lf->num_points)
next = lp->p.x; next = lp->p.x;
else else
next = NSMinX(lf->rect); next = NSMinX(lf->rect);
lp--; /* Valid since we checked for !i above. */ lp--; /* Valid since we checked for !i above. */
r = run_for_glyph_index(lp->pos, glyphs, &glyph_pos, &char_pos); r = run_for_glyph_index(lp->pos, glyphs, &glyph_pos, &char_pos);
@ -695,29 +695,30 @@ anything visible
last_visible = lf->pos; last_visible = lf->pos;
for (j = lp->pos - glyph_pos; j + glyph_pos < lp->pos + lp->length;) for (j = lp->pos - glyph_pos; j + glyph_pos < lp->pos + lp->length;)
{ {
if (r->glyphs[j].isNotShown || r->glyphs[j].g == NSControlGlyph || // Don't ignore invisble glyphs.
!r->glyphs[j].g) // if (r->glyphs[j].isNotShown || r->glyphs[j].g == NSControlGlyph ||
{ if (!r->glyphs[j].g)
GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos) {
continue; GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos)
} continue;
last_visible = j + glyph_pos; }
last_visible = j + glyph_pos;
cur = prev + [r->font advancementForGlyph: r->glyphs[j].g].width; cur = prev + [r->font advancementForGlyph: r->glyphs[j].g].width;
if (j + glyph_pos + 1 == lp->pos + lp->length && next > cur) if (j + glyph_pos + 1 == lp->pos + lp->length && next > cur)
cur = next; cur = next;
if (cur >= point.x) if (cur >= point.x)
{ {
*partialFraction = (point.x - prev) / (cur - prev); *partialFraction = (point.x - prev) / (cur - prev);
if (*partialFraction < 0) if (*partialFraction < 0)
*partialFraction = 0; *partialFraction = 0;
return j + glyph_pos; return j + glyph_pos;
} }
prev = cur; prev = cur;
GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos) GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos)
} }
*partialFraction = 1; *partialFraction = 1;
return last_visible; return last_visible;
} }

View file

@ -1793,7 +1793,8 @@ here. */
TODO: make sure this is only called when _layoutManager is known non-nil, TODO: make sure this is only called when _layoutManager is known non-nil,
or add guards or add guards
*/ */
- (unsigned int) characterIndexForPoint: (NSPoint)point - (unsigned int) _characterIndexForPoint: (NSPoint)point
respectFraction: (BOOL)respectFraction
{ {
unsigned index; unsigned index;
float fraction; float fraction;
@ -1808,13 +1809,22 @@ or add guards
return (unsigned int)-1; return (unsigned int)-1;
index = [_layoutManager characterIndexForGlyphAtIndex: index]; index = [_layoutManager characterIndexForGlyphAtIndex: index];
if (fraction > 0.5 && index < [_textStorage length]) if (respectFraction && fraction > 0.5 && index < [_textStorage length] &&
[[_textStorage string] characterAtIndex:index] != '\n')
{ {
index++; index++;
} }
return index; return index;
} }
// This method takes screen coordinates as input.
- (unsigned int) characterIndexForPoint: (NSPoint)point
{
point = [[self window] convertScreenToBase: point];
point = [self convertPoint:point fromView: nil];
return [self _characterIndexForPoint: point respectFraction: NO];
}
- (NSRange) markedRange - (NSRange) markedRange
{ {
return NSMakeRange(NSNotFound, 0); return NSMakeRange(NSNotFound, 0);
@ -4260,14 +4270,15 @@ other than copy/paste or dragging. */
NSRange range; NSRange range;
if (_tf.isDragTarget == NO) if (_tf.isDragTarget == NO)
{ {
_tf.isDragTarget = YES; _tf.isDragTarget = YES;
_dragTargetSelectionRange = [self selectedRange]; _dragTargetSelectionRange = [self selectedRange];
} }
dragPoint = [sender draggingLocation]; dragPoint = [sender draggingLocation];
dragPoint = [self convertPoint: dragPoint fromView: nil]; dragPoint = [self convertPoint: dragPoint fromView: nil];
dragIndex = [self characterIndexForPoint: dragPoint]; dragIndex = [self _characterIndexForPoint: dragPoint
respectFraction: YES];
dragRange = NSMakeRange (dragIndex, 0); dragRange = NSMakeRange (dragIndex, 0);
range = [self selectionRangeForProposedRange: dragRange range = [self selectionRangeForProposedRange: dragRange
@ -4295,14 +4306,15 @@ other than copy/paste or dragging. */
NSRange range; NSRange range;
if (_tf.isDragTarget == NO) if (_tf.isDragTarget == NO)
{ {
_tf.isDragTarget = YES; _tf.isDragTarget = YES;
_dragTargetSelectionRange = [self selectedRange]; _dragTargetSelectionRange = [self selectedRange];
} }
dragPoint = [sender draggingLocation]; dragPoint = [sender draggingLocation];
dragPoint = [self convertPoint: dragPoint fromView: nil]; dragPoint = [self convertPoint: dragPoint fromView: nil];
dragIndex = [self characterIndexForPoint: dragPoint]; dragIndex = [self _characterIndexForPoint: dragPoint
respectFraction: YES];
dragRange = NSMakeRange (dragIndex, 0); dragRange = NSMakeRange (dragIndex, 0);
range = [self selectionRangeForProposedRange: dragRange range = [self selectionRangeForProposedRange: dragRange
@ -4416,7 +4428,8 @@ other than copy/paste or dragging. */
possible) */ possible) */
startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil]; startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil];
startIndex = [self characterIndexForPoint: startPoint]; startIndex = [self _characterIndexForPoint: startPoint
respectFraction: [theEvent clickCount] == 1];
if (startIndex == (unsigned int)-1) if (startIndex == (unsigned int)-1)
{ {
@ -4620,8 +4633,9 @@ other than copy/paste or dragging. */
point = [self convertPoint: [lastEvent locationInWindow] point = [self convertPoint: [lastEvent locationInWindow]
fromView: nil]; fromView: nil];
proposedRange = MakeRangeFromAbs([self characterIndexForPoint: point], proposedRange = MakeRangeFromAbs([self _characterIndexForPoint: point
startIndex); respectFraction: YES],
startIndex);
chosenRange = [self selectionRangeForProposedRange: proposedRange chosenRange = [self selectionRangeForProposedRange: proposedRange
granularity: granularity]; granularity: granularity];
[self setSelectedRange: chosenRange affinity: affinity [self setSelectedRange: chosenRange affinity: affinity