mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 05:30:54 +00:00
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:
parent
347b646c1d
commit
9a371e74bd
4 changed files with 165 additions and 126 deletions
|
@ -1582,30 +1582,31 @@ void NSBeginInformationalAlertSheet(NSString *title,
|
|||
{
|
||||
GSAlertPanel *panel;
|
||||
NSString *title;
|
||||
unsigned nbut = [_buttons count];
|
||||
|
||||
panel = [[GSAlertPanel alloc] init];
|
||||
_window = panel;
|
||||
|
||||
switch (_style)
|
||||
{
|
||||
case NSCriticalAlertStyle:
|
||||
title = @"Critical";
|
||||
break;
|
||||
case NSInformationalAlertStyle:
|
||||
title = @"Information";
|
||||
break;
|
||||
case NSWarningAlertStyle:
|
||||
default:
|
||||
title = @"Alert";
|
||||
break;
|
||||
}
|
||||
{
|
||||
case NSCriticalAlertStyle:
|
||||
title = @"Critical";
|
||||
break;
|
||||
case NSInformationalAlertStyle:
|
||||
title = @"Information";
|
||||
break;
|
||||
case NSWarningAlertStyle:
|
||||
default:
|
||||
title = @"Alert";
|
||||
break;
|
||||
}
|
||||
[panel setTitleBar: title
|
||||
icon: _icon
|
||||
title: _informative_text
|
||||
message: _message_text
|
||||
def: [[_buttons objectAtIndex: 0] title]
|
||||
alt: [[_buttons objectAtIndex: 1] title]
|
||||
other: [[_buttons objectAtIndex: 2] title]];
|
||||
icon: _icon
|
||||
title: _informative_text
|
||||
message: _message_text
|
||||
def: (nbut > 0) ? [[_buttons objectAtIndex: 0] title] : (NSString*)nil
|
||||
alt: (nbut > 1) ? [[_buttons objectAtIndex: 1] title] : (NSString*)nil
|
||||
other: (nbut > 2) ? [[_buttons objectAtIndex: 2] title] : (NSString*)nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,17 +147,17 @@ withContentsOfURL: (NSURL *)url
|
|||
{
|
||||
if ([self readFromURL: url
|
||||
ofType: type
|
||||
error: error])
|
||||
error: error])
|
||||
{
|
||||
if (forUrl != nil)
|
||||
{
|
||||
[self setFileURL: forUrl];
|
||||
}
|
||||
}
|
||||
if (forUrl != nil)
|
||||
{
|
||||
[self setFileURL: forUrl];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DESTROY(self);
|
||||
}
|
||||
DESTROY(self);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -233,7 +233,12 @@ withContentsOfURL: (NSURL *)url
|
|||
{
|
||||
[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]];
|
||||
}
|
||||
|
||||
|
@ -269,6 +274,7 @@ withContentsOfURL: (NSURL *)url
|
|||
else
|
||||
{
|
||||
ASSIGN(_file_url, url);
|
||||
ASSIGN(_file_name, (url && [url isFileURL]) ? [url path] : (NSString*)nil);
|
||||
[self setLastComponentOfFileName: [[_file_url path] lastPathComponent]];
|
||||
}
|
||||
}
|
||||
|
@ -537,6 +543,7 @@ withContentsOfURL: (NSURL *)url
|
|||
{
|
||||
if (OVERRIDDEN(dataRepresentationOfType:))
|
||||
{
|
||||
*error = nil;
|
||||
return [self dataRepresentationOfType: type];
|
||||
}
|
||||
|
||||
|
@ -569,6 +576,7 @@ withContentsOfURL: (NSURL *)url
|
|||
|
||||
if (OVERRIDDEN(fileWrapperRepresentationOfType:))
|
||||
{
|
||||
*error = nil;
|
||||
return [self fileWrapperRepresentationOfType: type];
|
||||
}
|
||||
|
||||
|
@ -654,6 +662,7 @@ withContentsOfURL: (NSURL *)url
|
|||
{
|
||||
if (OVERRIDDEN(loadFileWrapperRepresentation:ofType:))
|
||||
{
|
||||
*error = nil;
|
||||
return [self loadFileWrapperRepresentation: wrapper ofType: type];
|
||||
}
|
||||
|
||||
|
@ -665,6 +674,7 @@ withContentsOfURL: (NSURL *)url
|
|||
}
|
||||
|
||||
// FIXME: Set error
|
||||
*error = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -678,8 +688,9 @@ withContentsOfURL: (NSURL *)url
|
|||
|
||||
if (OVERRIDDEN(readFromFile:ofType:))
|
||||
{
|
||||
return [self readFromFile: [url path] ofType: type];
|
||||
}
|
||||
*error = nil;
|
||||
return [self readFromFile: [url path] ofType: type];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSFileWrapper *wrapper = AUTORELEASE([[NSFileWrapper alloc] initWithPath: fileName]);
|
||||
|
@ -691,6 +702,7 @@ withContentsOfURL: (NSURL *)url
|
|||
}
|
||||
|
||||
// FIXME: Set error
|
||||
*error = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -817,17 +829,20 @@ withContentsOfURL: (NSURL *)url
|
|||
if (OVERRIDDEN(writeWithBackupToFile:ofType:saveOperation:))
|
||||
{
|
||||
if (saveOp == NSAutosaveOperation)
|
||||
{
|
||||
saveOp = NSSaveToOperation;
|
||||
}
|
||||
{
|
||||
saveOp = NSSaveToOperation;
|
||||
}
|
||||
|
||||
*error = nil;
|
||||
return [self writeWithBackupToFile: [url path]
|
||||
ofType: type
|
||||
saveOperation: saveOp];
|
||||
ofType: type
|
||||
saveOperation: saveOp];
|
||||
}
|
||||
|
||||
if (!isNativeType || (url == nil))
|
||||
{
|
||||
// FIXME: Set error
|
||||
*error = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -835,21 +850,22 @@ withContentsOfURL: (NSURL *)url
|
|||
{
|
||||
if ([url isFileURL])
|
||||
{
|
||||
NSString *newFileName;
|
||||
NSString *newFileName;
|
||||
|
||||
newFileName = [url path];
|
||||
if ([fileManager fileExistsAtPath: newFileName])
|
||||
{
|
||||
backupFilename = [self _backupFileNameFor: newFileName];
|
||||
newFileName = [url path];
|
||||
if ([fileManager fileExistsAtPath: newFileName])
|
||||
{
|
||||
backupFilename = [self _backupFileNameFor: newFileName];
|
||||
|
||||
if (![self _writeBackupForFile: newFileName
|
||||
toFile: backupFilename])
|
||||
{
|
||||
// FIXME: Set error.
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (![self _writeBackupForFile: newFileName
|
||||
toFile: backupFilename])
|
||||
{
|
||||
// FIXME: Set error.
|
||||
*error = nil;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (![self writeToURL: url
|
||||
|
@ -891,16 +907,20 @@ withContentsOfURL: (NSURL *)url
|
|||
|
||||
if (OVERRIDDEN(writeToFile:ofType:))
|
||||
{
|
||||
return [self writeToFile: [url path] ofType: type];
|
||||
*error = nil;
|
||||
return [self writeToFile: [url path] ofType: type];
|
||||
}
|
||||
|
||||
wrapper = [self fileWrapperOfType: type
|
||||
error: error];
|
||||
if (wrapper == nil)
|
||||
{
|
||||
// FIXME: Set error
|
||||
*error = nil;
|
||||
return NO;
|
||||
}
|
||||
|
||||
*error = nil;
|
||||
return [wrapper writeToFile: [url path] atomically: YES updateFilenames: YES];
|
||||
}
|
||||
|
||||
|
@ -913,9 +933,10 @@ originalContentsURL: (NSURL *)orig
|
|||
if (OVERRIDDEN(writeToFile:ofType:originalFile:saveOperation:))
|
||||
{
|
||||
if (saveOp == NSAutosaveOperation)
|
||||
{
|
||||
saveOp = NSSaveToOperation;
|
||||
}
|
||||
{
|
||||
*error = nil;
|
||||
saveOp = NSSaveToOperation;
|
||||
}
|
||||
|
||||
return [self writeToFile: [url path]
|
||||
ofType: type
|
||||
|
@ -954,9 +975,9 @@ originalContentsURL: (NSURL *)orig
|
|||
}
|
||||
|
||||
- (void)runModalSavePanelForSaveOperation: (NSSaveOperationType)saveOperation
|
||||
delegate: (id)delegate
|
||||
didSaveSelector: (SEL)didSaveSelector
|
||||
contextInfo: (void *)contextInfo
|
||||
delegate: (id)delegate
|
||||
didSaveSelector: (SEL)didSaveSelector
|
||||
contextInfo: (void *)contextInfo
|
||||
{
|
||||
NSString *fileName;
|
||||
|
||||
|
@ -1249,6 +1270,7 @@ originalContentsURL: (NSURL *)orig
|
|||
- (NSPrintOperation *)printOperationWithSettings: (NSDictionary *)settings
|
||||
error: (NSError **)error
|
||||
{
|
||||
*error = nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -1363,6 +1385,7 @@ originalContentsURL: (NSURL *)orig
|
|||
error:(NSError **)error
|
||||
{
|
||||
// FIXME: Implement. Should set NSFileExtensionHidden
|
||||
*error = nil;
|
||||
return [NSDictionary dictionary];
|
||||
}
|
||||
|
||||
|
@ -1483,7 +1506,7 @@ originalContentsURL: (NSURL *)orig
|
|||
meth = (void (*)(id, SEL, id, BOOL, void*))[delegate methodForSelector:
|
||||
didSaveSelector];
|
||||
if (meth)
|
||||
meth(delegate, didSaveSelector, self, saved, contextInfo);
|
||||
meth(delegate, didSaveSelector, self, saved, contextInfo);
|
||||
}
|
||||
|
||||
return saved;
|
||||
|
@ -1501,18 +1524,18 @@ originalContentsURL: (NSURL *)orig
|
|||
[self displayName]);
|
||||
|
||||
if (result == NSAlertDefaultReturn)
|
||||
{
|
||||
if ([self revertToContentsOfURL: [self fileURL]
|
||||
ofType: [self fileType]
|
||||
error: &error])
|
||||
{
|
||||
[self updateChangeCount: NSChangeCleared];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self presentError: error];
|
||||
}
|
||||
}
|
||||
{
|
||||
if ([self revertToContentsOfURL: [self fileURL]
|
||||
ofType: [self fileType]
|
||||
error: &error])
|
||||
{
|
||||
[self updateChangeCount: NSChangeCleared];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self presentError: error];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Closes all the windows owned by the document, then removes itself
|
||||
|
|
|
@ -610,28 +610,28 @@ anything visible
|
|||
{
|
||||
/* The point is inside a rect; we're done. */
|
||||
if (NSPointInRect(point, lf->rect))
|
||||
break;
|
||||
break;
|
||||
|
||||
/* 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
|
||||
with the previous line frag rect. */
|
||||
if (NSMinY(lf->rect) > point.y)
|
||||
{
|
||||
/* 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
|
||||
line. Otherwise, we consider it to be before the first glyph on
|
||||
the current line. */
|
||||
if (i > 0)
|
||||
{
|
||||
*partialFraction = 1.0;
|
||||
return lf->pos - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*partialFraction = 0.0;
|
||||
return lf->pos;
|
||||
}
|
||||
}
|
||||
{
|
||||
/* 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
|
||||
line. Otherwise, we consider it to be before the first glyph on
|
||||
the current line. */
|
||||
if (i > 0)
|
||||
{
|
||||
*partialFraction = 1.0;
|
||||
return lf->pos - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
*partialFraction = 0.0;
|
||||
return lf->pos;
|
||||
}
|
||||
}
|
||||
/* 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
|
||||
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.)
|
||||
*/
|
||||
if (NSMaxY(lf->rect) >= point.y && NSMinX(lf->rect) > point.x)
|
||||
{
|
||||
*partialFraction = 0.0;
|
||||
return lf->pos;
|
||||
}
|
||||
{
|
||||
*partialFraction = 0.0;
|
||||
return lf->pos;
|
||||
}
|
||||
}
|
||||
|
||||
/* Point is after all line frags. */
|
||||
|
@ -684,9 +684,9 @@ anything visible
|
|||
unsigned j;
|
||||
|
||||
if (i < lf->num_points)
|
||||
next = lp->p.x;
|
||||
next = lp->p.x;
|
||||
else
|
||||
next = NSMinX(lf->rect);
|
||||
next = NSMinX(lf->rect);
|
||||
|
||||
lp--; /* Valid since we checked for !i above. */
|
||||
r = run_for_glyph_index(lp->pos, glyphs, &glyph_pos, &char_pos);
|
||||
|
@ -695,29 +695,30 @@ anything visible
|
|||
|
||||
last_visible = lf->pos;
|
||||
for (j = lp->pos - glyph_pos; j + glyph_pos < lp->pos + lp->length;)
|
||||
{
|
||||
if (r->glyphs[j].isNotShown || r->glyphs[j].g == NSControlGlyph ||
|
||||
!r->glyphs[j].g)
|
||||
{
|
||||
GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos)
|
||||
continue;
|
||||
}
|
||||
last_visible = j + glyph_pos;
|
||||
{
|
||||
// Don't ignore invisble glyphs.
|
||||
// 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;
|
||||
}
|
||||
last_visible = j + glyph_pos;
|
||||
|
||||
cur = prev + [r->font advancementForGlyph: r->glyphs[j].g].width;
|
||||
if (j + glyph_pos + 1 == lp->pos + lp->length && next > cur)
|
||||
cur = next;
|
||||
cur = prev + [r->font advancementForGlyph: r->glyphs[j].g].width;
|
||||
if (j + glyph_pos + 1 == lp->pos + lp->length && next > cur)
|
||||
cur = next;
|
||||
|
||||
if (cur >= point.x)
|
||||
{
|
||||
*partialFraction = (point.x - prev) / (cur - prev);
|
||||
if (*partialFraction < 0)
|
||||
*partialFraction = 0;
|
||||
return j + glyph_pos;
|
||||
}
|
||||
prev = cur;
|
||||
GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos)
|
||||
}
|
||||
if (cur >= point.x)
|
||||
{
|
||||
*partialFraction = (point.x - prev) / (cur - prev);
|
||||
if (*partialFraction < 0)
|
||||
*partialFraction = 0;
|
||||
return j + glyph_pos;
|
||||
}
|
||||
prev = cur;
|
||||
GLYPH_STEP_FORWARD(r, j, glyph_pos, char_pos)
|
||||
}
|
||||
*partialFraction = 1;
|
||||
return last_visible;
|
||||
}
|
||||
|
|
|
@ -1793,7 +1793,8 @@ here. */
|
|||
TODO: make sure this is only called when _layoutManager is known non-nil,
|
||||
or add guards
|
||||
*/
|
||||
- (unsigned int) characterIndexForPoint: (NSPoint)point
|
||||
- (unsigned int) _characterIndexForPoint: (NSPoint)point
|
||||
respectFraction: (BOOL)respectFraction
|
||||
{
|
||||
unsigned index;
|
||||
float fraction;
|
||||
|
@ -1808,13 +1809,22 @@ or add guards
|
|||
return (unsigned int)-1;
|
||||
|
||||
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++;
|
||||
}
|
||||
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
|
||||
{
|
||||
return NSMakeRange(NSNotFound, 0);
|
||||
|
@ -4260,14 +4270,15 @@ other than copy/paste or dragging. */
|
|||
NSRange range;
|
||||
|
||||
if (_tf.isDragTarget == NO)
|
||||
{
|
||||
_tf.isDragTarget = YES;
|
||||
_dragTargetSelectionRange = [self selectedRange];
|
||||
}
|
||||
{
|
||||
_tf.isDragTarget = YES;
|
||||
_dragTargetSelectionRange = [self selectedRange];
|
||||
}
|
||||
|
||||
dragPoint = [sender draggingLocation];
|
||||
dragPoint = [self convertPoint: dragPoint fromView: nil];
|
||||
dragIndex = [self characterIndexForPoint: dragPoint];
|
||||
dragIndex = [self _characterIndexForPoint: dragPoint
|
||||
respectFraction: YES];
|
||||
dragRange = NSMakeRange (dragIndex, 0);
|
||||
|
||||
range = [self selectionRangeForProposedRange: dragRange
|
||||
|
@ -4295,14 +4306,15 @@ other than copy/paste or dragging. */
|
|||
NSRange range;
|
||||
|
||||
if (_tf.isDragTarget == NO)
|
||||
{
|
||||
_tf.isDragTarget = YES;
|
||||
_dragTargetSelectionRange = [self selectedRange];
|
||||
}
|
||||
{
|
||||
_tf.isDragTarget = YES;
|
||||
_dragTargetSelectionRange = [self selectedRange];
|
||||
}
|
||||
|
||||
dragPoint = [sender draggingLocation];
|
||||
dragPoint = [self convertPoint: dragPoint fromView: nil];
|
||||
dragIndex = [self characterIndexForPoint: dragPoint];
|
||||
dragIndex = [self _characterIndexForPoint: dragPoint
|
||||
respectFraction: YES];
|
||||
dragRange = NSMakeRange (dragIndex, 0);
|
||||
|
||||
range = [self selectionRangeForProposedRange: dragRange
|
||||
|
@ -4416,7 +4428,8 @@ other than copy/paste or dragging. */
|
|||
possible) */
|
||||
|
||||
startPoint = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
||||
startIndex = [self characterIndexForPoint: startPoint];
|
||||
startIndex = [self _characterIndexForPoint: startPoint
|
||||
respectFraction: [theEvent clickCount] == 1];
|
||||
|
||||
if (startIndex == (unsigned int)-1)
|
||||
{
|
||||
|
@ -4620,8 +4633,9 @@ other than copy/paste or dragging. */
|
|||
|
||||
point = [self convertPoint: [lastEvent locationInWindow]
|
||||
fromView: nil];
|
||||
proposedRange = MakeRangeFromAbs([self characterIndexForPoint: point],
|
||||
startIndex);
|
||||
proposedRange = MakeRangeFromAbs([self _characterIndexForPoint: point
|
||||
respectFraction: YES],
|
||||
startIndex);
|
||||
chosenRange = [self selectionRangeForProposedRange: proposedRange
|
||||
granularity: granularity];
|
||||
[self setSelectedRange: chosenRange affinity: affinity
|
||||
|
|
Loading…
Reference in a new issue